I upgrade from rails from 3.2.13 to 4 and have encountered a problem updating models. I am trying to update only one attribute on a model where I only have an identifier, I also need validations and callbacks. This worked fine on rails 3, but I have problems with rails 4.
In rails 4, if I do this:
user = User.select(:id).first
user.first_name = 'name'
user.save!
I get an error message:
NoMethodError: undefined method `type_cast' for nil:NilClass
from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.0.3/lib/active_record/attribute_methods/time_zone_conversion.rb:10:in `type_cast'
If I run the same code in rails 3 first_name is updated and update_at is updated by current_time.
If on rails 4 I run:
user = User.select(:id, :updated_at).first
user.first_name = 'name'
user.save!
Everything is working fine.
, , updated_at , . . Rails 3 . , update_attributes, . , update_column, , .
, rails 4 update_column updated_at, .