#318 Upgrading to Rails 3.2
Jan 23, 2012 | 9 minutes | Rails 3.2
Rails 3.2 sports many new features including automatic explain queries, tagged logging, key-value store in Active Record, improved migration generator and more. Learn all about these new features in this episode.
Very useful screencast about upgrading, actually I've tried to do that few days ago and got stuck on dependencies, but I will try again. Thanks a lot!
The solution I did, was removing Gemfile.lock and running bundle install again. But I don't think this is good approach to achieve new version of rails.
This is fine actually. So you should not worry about it too much.
You don't need to remove the Gemfile.lock, just use
bundle update
. http://gembundler.com/man/bundle-update.1.htmlit doesn't work with mercury-rails yet, any suggestions ?
It does work!
Just bundle update and make sure you use the git branch as your source:
gem 'mercury-rails', :git => 'git://github.com/jejacks0n/mercury.git'
If you have problems see this github issue:
https://github.com/jejacks0n/mercury/issues/114
It's worth noting that older versions of RubyGems will report an invalid gemspec for rails 3.2.0. You can upgrade RubyGems to address this (
gem update --system
) or you can wait for 3.2.1, which will fix this. Details here.Indeed, Rails 3.2 requires rubygems 1.8.15. But JDBC adapters are broken w/ Rails 3.2, see https://github.com/jruby/activerecord-jdbc-adapter/issues/132
If you use JRuby, you'd better keep Rails 3.1 for now
Nice screencast again @Ryan! Maybe I'm late on this but when did the ruby hash MyModel.new(:test => "test1") turn into MyModel.new(test: "test1") . Obviously the latter is more readable/user friendly :)
ruby 1.9 thats why lol . Sorry, had to research it on my own :)
Had to add the psych gem to my gemfile to get rails 3.2 working with one of my apps for some reason...
What if I`m using :uuid as POST parameter? Is it going to work?
No, it's calling those methods on the request object (the one that has request.path, request.remote_ip, etc).
You mentioned the config.log_tags .. Are these only params passed in via the 'params' hash? I wanted to include in there the method that is being used to output the data to the logger.
For example, if I had a model called 'Foo', I would want the logger to print out "[Foo] blah blah blah".
Is this possible, and if so, do you know where the docs are or how I can do this?
Thanks for the awesome screencast (as always).
I never knew that you could use underscore (_) to retrieve the last returned value in the console. Nice trick! (See the video around 2:23).
http://rubyquicktips.com/post/342527837/console-tip-retrieve-the-last-return-value-with
+1
Has anyone had issues in production on Heroku with compass 0.12.alpha?
https://github.com/chriseppstein/compass/issues/654#issuecomment-3661444
Is it just me or can we not access the new key/value store attribute in a rake task? I'm trying to set values of some keys in a kv store attribute, and I'm getting an unknown attribute error.
However, I have no such issue when I access or try to set the same attributes via the console.
I also tried to set values in the class initialize method, which works fine in Rails and the console. I get the same error when the class in initialized in a rake task.
Any ideas?
Make sure your Rake task is loading the full Rails environment:
task :foo => :environment
. It should have access to the key/value store then.Yes I do have the environment loaded as you've suggested, that's why I don't understand why this doesn't work. I'm going to try
bundle exec
to run the rake task when I get back to that project and see if that helps at all.I've also tried with and without
attr_accessible
, makes no difference, still get the error.I wonder why no one mentions the command rake rails:update - even the Rails 3.2 release notes don't.
So one thing about using "store" is that it doesn't transparently work for the .to_json calls.
For example:
store :properties, accessors: [:blah]
If you do:
@things.to_json(:only => [:blah])
You'll get back
[{},{}]
If you do:
@things.to_json
You'll get:
[{properties: {blah: "foo"}}]
Which just isn't as convenient for merging in with your "standard" backbone.js or other JSON related infrastructure.
I'm not sure if there' a better way using to_json, but I'm guessing you can rescue the situation using say jbuilder or writing your own to_json call.
I'd be glad to hear better ideas though!
Full of information for upgrading!
Is there any reason for putting the following line in config/environments/development.rb by default?
=# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
The rails app is going to throw out mass_assignment error if a protected attribute is submitted on a form. I can not think of a good reason for doing that by default in development.