我有一個表格結構,它使用鏈接表將作業與人員關聯起來,鏈接表格包含一個人在特定工作中需要多長時間的數據信息。使用鏈接表的Activerecord以及其他信息
我有一個是試圖讓所有的作業和顯示作業的就業日期範圍簡單的Rails應用程序。
class Employment < ActiveRecord::Base
belongs_to :person
belongs_to :job
end
class Job < ActiveRecord::Base
belongs_to :employer
has_many :employment
accepts_nested_attributes_for :employment
end
def index
@jobs = Job.joins(:employment).find(:all)
end
現在,當我嘗試訪問的屬性「employment_started」 /落幕我收到了「在體驗#指數NoMethodError」
undefined method `employment_started' for #<Class:0x000000026927e0>
17: <span><%=job.employment.employment_started%> - <%=job.employment.to_yaml%>
當我使用「to_yaml」功能,我可以看到有數據在對象中:
!ruby/object:Employment attributes: job_id: 1 person_id: 1 employment_started: 2008-04-21 employment_ended: attributes_cache: {} changed_attributes: {} destroyed: false marked_for_destruction: false new_record: false previously_changed: {} readonly: false
爲什麼rails不能訪問這個3'rd級別的屬性?
良好的捕捉,哈哈...爲什麼to_yaml不顯示類型作爲集合?有沒有更簡單的方法來轉儲有關動態對象的信息? – 2011-03-18 21:12:28