2013-01-22 29 views
0

我有了這個代碼在我的比賽指數:Ruby on Rails的 - 如何從一個封閉的回憶的方法不阻止

<table> 
<% @matches.each do |match| %> 
    <tr> 
    <td><%= match.team_a %></td> 
    <td><%= match.team_b %></td> 
    <td><%= match.score_a %> - <%= match.score_b %></td> 
    <td><%= match.field %></td> 
    <%= render "shared/asterisk_message", :target => [match.team_b, match.team_a] %> 
<% end %> 
</table> 

我想移動渲染asterisk_message 表,但是這就意味着把它放在<% end %>後,這顯然給了我這個錯誤:

undefined local variable or method `match' for #<#:0xb6da40d8>

我怎麼能做出來?

+0

但是......'match'不會使表的範圍之外的任何意義嗎?你想要多於一個'shared/asterisk_message'嗎? – Xymostech

+1

再次迭代邊桌和渲染 – Amar

+0

@Xymostech我不想渲染另一個'shared/asterisk_message',我想把我已經得到的**移到桌子外面。否則,'match'在'do'塊之外是沒有任何意義的(除非像@SaurabhJain和@Amar建議的那樣,我們在table外面重複「do」塊)。 –

回答

1

嘗試:

<table> 
    <% @matches.each do |match| %> 
     <tr> 
     <td><%= match.team_a %></td> 
     <td><%= match.team_b %></td> 
     <td><%= match.score_a %> - <%= match.score_b %></td> 
     <td><%= match.field %></td> 
     <%= render "shared/asterisk_message", :target => [match.team_b, match.team_a] %> 
    <% end %> 
    </table> 

<% @matches.each do |match| %> 
<%= render "shared/asterisk_message", :target => [match.team_b, match.team_a] %> 
<% end %> 
+0

謝謝,這是我想知道的(以及我也想學的東西)。 –