0

我已经设置了一个 Rails 项目:用户->项目->示例

当我将我的项目视为表格时,一切都很好。我渲染一个表格模板:

<%= render 'layouts/projects_table' %>

但是当我为一个项目渲染我的样本时

<%= render 'layouts/samples_table' %>

我得到了表格,但在表格之前我得到了我的原始数据:

[#<Sample id: 28, name: "abcd", size: 11, quantity: 11.0, created_at: "2013-04-04 09:58:50"> ... ]

项目控制器:

def show
  @project = Project.find(params[:id])
  @samples = @project.samples
end

_samples_table:

<table id="samples" class="display">
<thead>
    <tr>
        <th>
            Sample Name
        </th>
        <th>
            Size
        </th>
        <th>
            Quantity
        </th>
        <th>


        </th>
    </tr>
</thead>
<tbody>
    <%= @samples.each do |sample| %>
        <tr>
            <td>
                <%= link_to sample.name, project_sample_path(@project, sample) %>
            </td>
            <td>
                <%= sample.size %>
            </td>
            <td>
                <%= sample.quantity %>
            </td>

            <td>
                <% if !sample.libraries.any?%>
                <%= link_to 'Del', project_sample_path(@project, sample), 
                    :confirm => 'Are you sure?', :method => :delete %>
                <% end %>
            </td>
        </tr>
    <% end %>
</tbody>

其他一切正常。任何帮助,将不胜感激!

奥利弗

4

2 回答 2

1

=从循环定义中删除

<%= @samples.each do |sample| %>

应该

<% @samples.each do |sample| %>
于 2013-04-08T15:23:34.953 回答
1

您正在输出.each.

<%= @samples.each do |sample| %>

应该

<% @samples.each do |sample| %>
于 2013-04-08T15:23:41.963 回答