I encountered the same error. This is not that ActiveRecord is missing #to_i, but something else that in my case is related to the factory_girl stone.
factory_girl (4.1.0) factory_girl_rails (4.1.0)
Here's an isolated case of difference:
rails _3.1.0_ new rails31 cd rails31 bundle install rails g scaffold note title:string contents:text rails g scaffold user name:string rails g migration add_user_id_to_notes user_id:integer rake db:migrate
Then in the console:
require 'factory_girl' FactoryGirl.define { factory :note } Factory(:note, :user_id => User.first, :title => 'foo') User Load (0.1ms) SELECT "users".* FROM "users" LIMIT 1 SQL (0.5ms) INSERT INTO "notes" ("contents", "created_at", "title", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["contents", nil], ["created_at", Sun, 13 Jan 2013 21:29:36 UTC +00:00], ["title", "foo"], ["updated_at", Sun, 13 Jan 2013 21:29:36 UTC +00:00], ["user_id", 1]] => #<Note id: 3, title: "foo", contents: nil, created_at: "2013-01-13 21:29:36", updated_at: "2013-01-13 21:29:36", user_id: 1>
However, if I do the same sequence of steps with:
rails _3.2.11_ new rails3211
Then in the console I see:
1.9.2-p290 :001 > require 'factory_girl' => true 1.9.2-p290 :002 > FactoryGirl.define { factory :note } => [] 1.9.2-p290 :003 > Factory(:note, :user_id => User.first, :title => 'foo') User Load (0.1ms) SELECT "users".* FROM "users" LIMIT 1 (0.0ms) begin transaction SQL (24.5ms) INSERT INTO "notes" ("contents", "created_at", "title", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["contents", nil], ["created_at", Sun, 13 Jan 2013 21:33:03 UTC +00:00], ["title", "foo"], ["updated_at", Sun, 13 Jan 2013 21:33:03 UTC +00:00], ["user_id", nil]] (2.4ms) commit transaction =>
Pay attention to nil user_id for Rails 3.2.11