Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails表视图表示法_Ruby On Rails 3_View - Fatal编程技术网

Ruby on rails 3 Rails表视图表示法

Ruby on rails 3 Rails表视图表示法,ruby-on-rails-3,view,Ruby On Rails 3,View,我正在尝试构建以下表视图: +----------+Actor 1+Actor 2+Actor 3+ + REQ 1 + X + + X + + REQ 2 + + X + X + + REQ 3 + X + X + X + + REQ 4 + + + + +----------------------------------+ 我目前有以下代码(但不确定

我正在尝试构建以下表视图:

+----------+Actor 1+Actor 2+Actor 3+
+ REQ 1    +   X   +       +    X  +
+ REQ 2    +       +   X   +    X  +
+ REQ 3    +   X   +   X   +    X  +
+ REQ 4    +       +       +       +
+----------------------------------+
我目前有以下代码(但不确定如何构建):


引发异常:
未定义nil:NilClass的“排序依据”方法


感谢您的帮助。

已解决:以下是工作代码

在控制器中

def method_name
  @project = Project.includes(:requirements => [:actors]).find(params[:id])
  @actors = @project.actors.index_by(&:id)
end
在视图中

<table class="table table-striped">
  <tr>
    <th></th>
    <% @actors.values.each do |actor| %>
      <th><%= actor.name.titleize %></th>
    <% end %>
  </tr>

  <% @project.requirements.order('position').each do |requirement, actors| %>
    <% hash = requirement.actors.index_by(&:id) %>
    <tr>
      <td><%= link_to requirement.name_for_display, project_requirement_path(@project, requirement) %></td>
      <% @actors.keys.each do |id| %>
        <td><%= hash[id].present? ? "X" : nil %></td>
      <% end %>
    </tr>
  <% end %>
</table>


actors
为零-块参数不会将其设置为任何值,它只是将
req
设置为需求。不确定数据模型的外观,但可能需要从需求中提取参与者数据。参与者与
ActorsRequirements
表相关。不确定如何正确提取和渲染。
<table class="table table-striped">
  <tr>
    <th></th>
    <% @actors.values.each do |actor| %>
      <th><%= actor.name.titleize %></th>
    <% end %>
  </tr>

  <% @project.requirements.order('position').each do |requirement, actors| %>
    <% hash = requirement.actors.index_by(&:id) %>
    <tr>
      <td><%= link_to requirement.name_for_display, project_requirement_path(@project, requirement) %></td>
      <% @actors.keys.each do |id| %>
        <td><%= hash[id].present? ? "X" : nil %></td>
      <% end %>
    </tr>
  <% end %>
</table>