2013-04-08 67 views
0

我的原始数据,我设置Rails项目: 用户 - >项目 - >样品Rails的呈现在HTML

当我认为我的项目如表,一切都很好。我渲染表模板:

<%= 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> 

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

奥利弗

+1

您需要向我们展示你的'samples_table'视图的代码。 – jdl 2013-04-08 15:17:16

回答

1

从循环定义

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

取出=应该

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

非常感谢。我已完全监督这个... ;-) – user2258116 2013-04-08 15:27:47

+1

Upvote /单击复选标记以接受答案。 – deefour 2013-04-08 15:32:40

1

你输出的.each返回值。

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

应该

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