开发者

Why ActiveModel is not returning the attribute value

开发者 https://www.devze.com 2023-04-03 12:39 出处:网络
I am using Rails 3.0.10 class Friend attr_accessor :first_name, :last_name, :ema开发者_运维问答il

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

精彩评论

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