我写了下面的类:收到ActiveRecord的关系,但需要对象
class Occupation < ActiveRecord::Base
has_many :pref_labels
has_many :cv_occupations
has_many :cvs, :through => :cv_occupations
validates_uniqueness_of :uri
# This function will return the specified label for the given language.
def label(language = Language.find_or_create_by_code(:en))
self.pref_labels.where("language_id = #{language.id}")
end
end
class PrefLabel < ActiveRecord::Base
belongs_to :language
belongs_to :concept
belongs_to :skill
belongs_to :occupation
validates_uniqueness_of :value, :scope => [:language_id, :value]
validates_uniqueness_of :language_id, :scope => [:language_id, :value]
end
在我看来,我把以下内容:%TD = occupation.label(@language) 但这种回报作为错误:
undefined method `value' for #<ActiveRecord::Relation:0x80c8368>
我怎样才能得到真正的对象返回而不是关系?我知道这事做与延迟加载....
后也控制器的操作代码 – Bohdan 2011-05-05 13:23:39