I typically write something like this:
class Person < ActiveRecord::Base
attr_accessible :first_name, :last_name
def name
"#{ first_name } #{ last_name }"
end
def name=(str)
first, last = str.split(' ', 2)
write_attribute :first_name, first
write_attribute :last_name, last
end
end
Which allows you to do Person.new(:name => "Adam Lassek") instead of splitting it up in the controller.
In Rails 3.1.0.rc4-5, this gives me the WARNING: Can't mass-assign protected attributes: name error.
This used to work. What changed?
add name to the attr_accessible