2017-08-23 71 views
0

我想在本地體驗下展示相關體驗。我試圖用@experiences= Experience.excludes(house.experiences)來做,但沒有解決。我可以得到任何建議如何做到這一點。如何顯示相關項目

<h3>Local experiences</h3> 

<section class="list-box"> 
    <% @house.experiences.each do |experience| %> 

    <p> 
    <%= experience.name %> 
    <% if logged_in? && current_user.role == "customer" %> 
    <%= link_to "Make Enquiry", new_message_path(receiver_id: experience.supplier.user) %> 
    <% else %> 
    <%= link_to "Make Enquiry", new_customer_path %> 
    <% end %> 
    </p> 
    <% end %> 
</section> 

<h3>Related experiences</h3> 

<section class="list-box"> 
    <% @experiences.each do |experience| %> 

    <p> 
    <%= experience.name %> 
    <% if logged_in? && current_user.role == "customer" %> 
    <%= link_to "Make Enquiry", new_message_path(receiver_id: experience.supplier.user) %> 
    <% else %> 
    <%= link_to "Make Enquiry", new_customer_path %> 
    <% end %> 
    </p> 
    <% end %> 
</section> 
+0

什麼是*排除*?而你的意思是*沒有解決*? – Pavan

+0

_but did not work out_什麼是錯誤? – Roshan

+0

排除僅僅是相反的包含方法是rails和它看起來像你想排除每個房子的經驗ryt?我想知道房子和經驗如何相關在DB(has_many或has_one)? – VKatz

回答

0

在rails模型中沒有叫做excludes的方法。只有exclude?,這是類String的實例方法。請參閱here

對於你的問題,或許下面的東西會起作用house_id是你體驗表中的foreign_key。

@experiences = Experience.where.not(house_id: house.experiences) 

你可以參考here更多not條件。

相關問題