Rails以html呈现我的原始数据

时间:2013-04-08 15:14:06

标签: ruby-on-rails

我已经设置了一个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"> ... ]

ProjectsController:

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>

其他一切都很好。 任何帮助将不胜感激!

奥利弗

2 个答案:

答案 0 :(得分:1)

从循环定义中删除=

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

应该是

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

答案 1 :(得分:1)

您输出的返回值为.each

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

应该是

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