我有用户模型和两个子类 Developer 和 Buyer(子模型)。在每个模型中,我都有恒定的字段。
在模型用户
class User < ActiveRecord::Base
attr_accessor *:get_fields
after_initialize :get_additional_fields
# FIELDS for current class
def self.get_fields
Object.const_get( self.name )::FIELDS
end
# set additional fields
#
def get_additional_fields
self.country = 'text'
end
end
我有一些错误NoMethodError: undefined methodcountry=' for #<Developer:
我的错误是什么?
更新
class Buyer < User
FIELDS = [ :country, :avatar ]
end
class Developer < User
FIELDS = [ :country, :avatar, :location, :first_name, :last_name ]
end
我的请求d = Developer.first