显示表"显示"使用相同相关ID

时间:2015-06-22 15:02:03

标签: ruby-on-rails ruby

我想在完成添加内容时显示其他相关项目。

我有一个普通的crud脚手架,所以当我添加一个" Task"这与项目有关,我想在重定向到" Show"到桌子上形成一个显示其他"任务"相同的相关项目......

show.html.erb

<table>
<thead>
<tr>
  <th>Seq</th>
  <th>Descr</th>
  <th>Seqpai</th>
  <th>Type</th>
  <th>Hour</th>
  <th>Pid</th>
  <th colspan="3"></th>
  </tr>
  </thead>

 <tbody>
 <% @lookup.each do |lookup| %>
  <tr>
    <td><%= task.seq %></td>
    <td><%= task.descr %></td>
    <td><%= task.seqpai %></td>
    <td><%= task.typo %></td>
    <td><%= task.hour %></td>
    <td><%= task.projeto.name %></td>
  </tr>
<% end %>
</tbody>

tasks controller =&gt;

def lookup
@taskete = Task.where(@projeto_id)
end

属于Projeto和Projeto的任务有很多任务

2 个答案:

答案 0 :(得分:0)

我不明白这个问题是什么。但是如果您的控制器的源代码定义了名为&#34; @taskete&#34;的变量,那么在视图中您将迭代&#34; @ lookup&#34;。

你的视图循环应该是:@taskete.each do | task |

答案 1 :(得分:0)

任务属于projecto,projecto有很多任务。因此,要显示当前任务的projecto的所有任务,请执行...

 <% @taskete.projecto.tasks.each do |task| %>

如果您只想显示其他任务(即不显示列表中的当前任务,只显示相关任务),您可能想要...

 <% @taskete.projecto.tasks.each do |task| %>
   <% next if @taskete == task %>

...如果集合中的任务是@tasketo

,它将跳过当前循环
相关问题