2013-04-08 62 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| %>