Upgrading to Rails 3.2.0 from Rails 3.1.3

Yup, finally it's here! :) Switching Susanoo (Senpuu v5) to 3.2 wasn't so hard. Took me about 5 hours. Why so long? Well because I had to fix my "special" Paperclip version and make so additional table names changes. All the steps are presented below. Enjoy.

Gemfile

gem "rails", '3.2.0'

group :assets do
  gem 'sass-rails', '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3', :require => 'uglifier'
end

Weird stuff

rename hash column hash is defined by ActiveRecord

I've got some problems with my attributes names. Looks like, you cannot use "hash" as an attribute name. Also weird stuff was happening with my "email_change" attribute. I could write to it but I could not retrieve values (always nil). Renaming those two attributes fixed problems. So just:

        rename_column :users, :email_change, :changed_at

Small fixes

Instead of:

set_table_name :table

use:

self.table_name= :table

Templates

Passing the format in the template name is deprecated. 
Please pass render with :formats => [:html] instead

When using render with a template we've been passing a template format. For example:

render "/shared/404.html", :status => 404, :layout => false

Now we don't need to provide the file format, instead we just do it like this:

render "/shared/404", :formats => [:html], :status => 404, :layout => false

Form builder doesn't accept range as a param :(

Don't know why this is not supported. When building forms, we cannot pass a range. Instead we must pass an array. So to fix it just perform to_a on a range:

# Won't work:
1..31
# Works like a charm:
(1..31).to_a

Write inheritable attribute

Last but not least, write_inheritable_attribute was removed so now instead of:

write_inheritable_attribute(:attribute_name, value)

we should use:

class_attribute :attribute_name
self.attribute_name = value

Categories: Rails, Ruby, Software

3 Comments

  1. The fact a form builder doesn’t accept a range was a regression, fixed on Rails 3.2.1. Everything else is right on spot! Thanks for writing this!

  2. I got burned with an attribute named “with_change”. Another column name that gave me trouble was “with”. I renamed both and it’s working now.

    Your post helped me, thanks.

  3. Be careful with the switch to class_attribute – it’s not at all the same as write_inheritable_attribute:

    http://martinciu.com/2011/07/difference-between-class_inheritable_attribute-and-class_attribute.html

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑