Why ActiveModel is not returning the attribute value
I am using Rails 3.0.10
class Friend
attr_accessor :first_name, :last_name, :ema开发者_运维问答il
extend ActiveModel::Naming
include ActiveModel::AttributeMethods
define_attribute_methods [:first_name, :last_name, :email]
include ActiveModel::Conversion
def persisted?; false; end
end
> Friend.new(:first_name => 'John').first_name
=> nil
What do I need to do to retrieve the first_name.
Don't you need an initializer?
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
The mass assignment stuff comes from ActiveRecord::Base, no?
精彩评论