2012-10-18 69 views
1

我希望顯示一個索引頁的記錄(標題)到另一個,爲了這個,我做一個索引頁的記錄未在另一索引頁顯示,軌道

在index.haml: -

-if @individual.important_event.present? 
    [email protected]_event.each do |event| 
    %p 
    = link_to event.title, important_events_path 

在individual.rb: -

has_many :important_event 

在important_event.rb: -

belongs_to :individual 

但它不起作用。它給錯誤「未定義的方法`每個」爲#< ImportantEvent:0xbb729c8>」

回答

3

在你individual.rb模型,需要使用複數在has_many聲明,就像這樣:

has_many :important_events 

然後你就可以在您看來,使用:[email protected]_events.each

搞清楚何時應該或不應該在Rails中使用複數是一種痛苦,即使英語是您的第一語言。

+0

+1雖然我不同意知道何時使用複數或單數是一種痛苦。 – Mischa

+0

謝謝您的幫助 –