Rails on Ruby 1.8.7

Although Ruby 1.8.7 is not officially recommended yet for Ruby on Rails, it does in fact work fine with Rails 2.1.  And version p22 contains all the latest security fixes.For what it’s worth, I can confirm that not only are our apps working well under 1.8.7 (including ferret and over 30,000 lines of app code), but they are consuming / leaking considerably less memory.  (They still do leak, but the rate is much reduced.)So upgrade now.Beware of one issue – we had to clean up our ERB code to not contain comments that are not specifically marked inside their own tags like <%# comment %> because of different handling in 1.8.7.

Advertisements

Rails 2.1.0 breakage

Rails 2.1.0 has many nice new features, but also it broke our app in some places.  This is what I found:1. setup_with_fixtures no longer does anythingPreviously we would use setup_with_fixtures in our tests to do setup actions, but it’s not called any more.  Just using plain old setup works for all our cases.2. render :locals=>{} – hash keys must be symbolsPreviously this would have worked

render :partial=>"something", :locals=>{"foo"=>"bar", "hoo"=>"haa"}

Now make sure all the locals are denoted by symbols

render :partial=>"something", :locals=>{:foo=>"bar", :hoo=>"haa"}

3. Relative paths when rendering actionsWe were using double dots in our template paths when rendering actions from another controller, like this:

render :action=>"../controller/template"

This no longer works: instead try this:

render :template=>"controller/template"

4. Non null text columns in mysql will not default to empty string automatically if default is not setIf you happen to have a column of type text in your mysql database that is set to be NOT NULL and does not have a default set, then previously you would have got away without having to set a value explicitly for the column before saving an AR object.This is not the case any more, ActiveRecord will set the value to nil/NULL and a database error will result when you try to save the object. So you need to set a value in your AR objects for these columns before saving. See here for details of the changes that cause this, and here for the associated bug report.5. @action_name is no longer available in viewsRails is now careful not to export into the views some instance variables that were previously available. But just omit the @ – there is a new method action_name for this purpose. Or you could use @controller.action_name, or of course params[:action] to get the same information. See here for details of this issue.6. Collection#size no longer works correctly on collections after they have been added to with buildBecause of a bug in collection#size, it does not report the correct value after you have added additional items using collection#build. This bug has existed pre 2.1.0, but has only become an issue because this changeset causes build no longer automatically loading the collection. When size tries to calculate the size of the collection it correctly counts the collection members in the DB, but incorrectly counts the added-but-not-saved members as just 1, no matter how many more than one have been added.I submitted a patch for this.That’s all the issues we saw, it’s all working fine now. Go and upgrade now! (But don’t try to use Ruby 1.8.7, at least not until this is fixed)