[英]How can I list a model when it belongs to a another model in rails?
I have two models: Day and Lecture, lecture belongs to day and day has many lectures, I want list all the lecture in each day:我有两个模型:Day 和 Lecture,talk 属于 day,day 有很多讲座,我想列出每天的所有讲座:
<% @days.each do |day| %>
<tr>
<td><%= day.name %></td>
<td><%= day.date %></td>
<td><%= link_to 'Destroy', day_path(day),
method: :delete,
data: { confirm: 'This will delete all the lectures in this day. Do you want to continue?' } %></td>
<br/>
<%= render @day.lectures %>
<br/>
</tr>
but it does not work with '@day.lectures'.但它不适用于“@day.lectures”。
btw, i already have _lecture.html.erb file and it should be a problem of how to write it.顺便说一句,我已经有了_lecture.html.erb 文件,应该是如何编写它的问题。 If not, I can put on my routes or more information.
如果没有,我可以提供我的路线或更多信息。 Thanks!
谢谢!
Remove @
from your @day
instance so that the line is从您的
@day
实例中删除@
,以便该行是
<%= render day.lectures %>
You're inside the iteration of @days
and each day is referenced as day
你在
@days
的迭代中,每一天都被称为day
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.