2016-07-12 2 views
0

私はいくつかのレポートのコードを書き留めようとしています。コードを書き留めようとしています - 変数が部分に渡されていません

私はテーブルのヘッダコードをとり、それを部分的に入れました。それは私がレンダリングの部分でそれを呼び出すとうまく動作します。しかし、テーブル本体のコードを移動しようとすると、「何かが間違っている」というエラーが表示されます。作品

私の元のコードは、私は、部分的にすることを移動し、私はエラーが表示部分

<% @complaints.each do |complaint| %> 
    <% if complaint.product_name == $complaint_group_name then %> 
    <%= render :partial => 'report_body' %> 
    <% end %> 
<% end %> 

をレンダリングしようとしてきたときに動作していないコードがある

<% @complaints.each do |complaint| %> 
    <% if complaint.product_name == $complaint_group_name then %> 
    <tr> 
     <td><%= link_to complaint.id, complaint %></td> 
     <td style="text-align: right;"><%= complaint.length %></td> 
     <td style="text-align: center;"><%= complaint.disposition %></td> 
     <td width="20%"><%= complaint.sales_order %></td> 
     . . . 
    <% end %> 
<% end %> 

です

I, [2016-07-12T10:25:09.046754 #95324] INFO -- : Rendered complaints/report_by_product.html.erb within layouts/application (359.4ms) 
I, [2016-07-12T10:25:09.046754 #95324] INFO -- : Completed 500 Internal Server Error in 375ms (ActiveRecord: 140.6ms) 
F, [2016-07-12T10:25:09.046754 #95324] FATAL -- : 
ActionView::Template::Error (undefined local variable or method `complaint' for #<#<Class:0x51caab8>:0x95242f8>): 
    1: 
    2: 
    3:   <tr> 
    4:   <td><%= link_to complaint.id, complaint %></td> 
    5:   <td style="text-align: right;"><%= complaint.length %></td> 
    6:   <td style="text-align: center;"><%= complaint.disposition %></td> 
    7:   <td width="20%"><%= complaint.sales_order %></td> 
    app/views/complaints/_report_body.html.erb:4:in `_app_views_complaints__report_body_html_erb__209592603_78833796' 

明らかに| complaint |ブロックの一部が部分的に認識されない。私はこれを渡すことができるか、部分的に含める必要がありますが、各レポートのグループ分けを部分的に処理する必要があるため、面倒です。

短い質問はできますか?部分的に?

答えて

1

部分的にローカル変数として '苦情' 渡すようにしてください:

render partial: 'report_body', locals: { complaint: complaint } 
+0

と同等である。この

<%= render 'report_body', complaint: complaint %> 

のような短い形式を使用することができますそれをやった。今、地元の人たちの仕組みを理解しています。 –

2

それとも、

<%= render partial: 'report_body', locals: { complaint: complaint } %> 
関連する問題