开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜