我在我的 Rails 应用程序中设置了一个 ActiveModel 类,如下所示:
class MyThingy
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
include ActiveModel::Conversion
attr_accessor :username, :favorite_color, :stuff
def initialize(params)
#Set up stuff
end
end
我真的希望能够做到这一点:
thingy = MyThingy.new(params)
thingy.update_attributes(:favorite_color => :red, :stuff => 'other stuff')
我可以自己编写 update_attributes,但我感觉它存在于某个地方。可以?