【发布时间】:2011-06-19 15:27:00
【问题描述】:
假设我们有一个 Post 模型、一个 User 模型和一个 View 模型。
当用户查看帖子时,会在 Views 表中创建一条新记录。该表链接用户、帖子和当前时间。稍后,如果该用户再次返回查看帖子,则记录会更新为新时间。很基本的东西。
帖子有_many视图,用户有_many视图 视图属于帖子和用户
在帖子的索引视图中,我想调用每个帖子的特定视图,即
<% @Posts.each do |post| %>
<%= post.name %><br/>
<%= post.views %> # This connects all of the views related to this post.
# How do I get the only one connected to this post and the current_user.id?
<% end %>
我觉得有一些简单的方法来完成这个我完全忘记了
【问题讨论】:
标签: ruby-on-rails ruby arrays ruby-on-rails-3