Prototype and script.aculo.us problems in Rails 1.2
Whilst working through the examples in the “Ajax on Rails” book I had all sorts of problems with Prototype and script.aculo.us. For a start, there is a simple example of a link that toggles a div between visible and invisible, like this:
<%= link_to_function "Toggle DIV", "$('indicator').toggle()" %>
But all I got with this was the error message “toggle is not a function. I even tried replacing toggle() with show() and got another error. Eventually I upgraded from Prototype 1.4 to 1.5 and the problem went away.
Now all through this, script.aculo.us had been working fine. But then I tried another simple example:
Effect.toggle('indicator', 'blind')
Again I got the error message that ‘toggle is not a function’. So this time I upgraded script.aculo.us to 1.7 and it all seems to work fine.
Having said that all I’ve done is upgrade within my current project so now I need to work out how to upgrade the prototype and script.aculo.us built into Rails so that all new projects start with the new versions.



March 5th, 2007 at 9:33 am
Rails 1.2 ships with prototype 1.5 and Scriptaculous 1.7 so if you upgraded to rails 1.2 and created a new rails project then you should have them in the public/javasctips directory of your project.
If you created a project with an older version of rails and then upgraded rails then this will not replace the javascript files in your project.
There are two ways to do this.
First, modify your config/environments.rb file to set the RAILS_GEM_VERSION variable to your new version of rails (1.2.2 at the moment)
Then run
rake rails:update:javascripts
to update the javascript files in the public/javascripts directory.
Another way (but probably more risky since it affects the whole project) is to run
rails .
in the project directory. This will then give you the option to replace out of date files. BEWARE that if you’re not careful you may replace files that you have modified losing your work!
September 27th, 2007 at 3:34 pm
I think this has been taken care of in the latest version of Rails.