我有User模型和两个子类Developer和Buyer(子模型)。在每个模型中,我都有不变的FIELDS。
在型号用户
中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