私は通常、次のようなものを書きます。
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
これによりPerson.new(:name => "Adam Lassek")
、コントローラーで分割する代わりに実行できます。
Rails 3.1.0.rc4-5では、これによりWARNING: Can't mass-assign protected attributes: name
エラーが発生します。
これは以前は機能していました。何が変わったの?