这已被多次询问,但在尝试了我能找到的所有解决方案之后,我不再接近我自己的解决方案了。
我有一部分,_form
- 这是相关部分:
<% @tournament.sub_tournaments.each do |sub| %>
<%= f.fields_for :sub_tournaments, sub, :validate => false do |sub_form| %>
...
<table>
...
<tbody>
<%= sub_form.fields_for :standings, :validate => false do |standings| %>
<%= render 'tournaments/form_partials/standing_fields', f: standings, sub: sub %> #here's the problem
<% end %>
</tbody>
</table>
...
<% end %>
<% end %>
在标记的行中,我试图将两个变量传递给给定的部分 - f: standings
和sub: sub
。如果我只传递f: standings
,页面加载正常,但是当我添加sub: sub
时,我收到以下错误:
undefined local variable or method `sub'
引用_standing_fields
partial:
<tr>
<td><%= f.hidden_field :_destroy %><%= f.text_field :standing, :class => "standing", readonly: true, :type => "" %></td>
<% if Game::TEAM_GAMES.include? sub.game.name %> #here's the problem
<td><%= f.grouped_collection_select(:team_division_id, Team.order(:name).includes(:team_divisions), :team_divisions, :name, :id, :game_name, include_blank: true)%></td>
<% else %>
<td><%= f.grouped_collection_select(:player_id, Player.order(:name).includes(:player), :player, :name, :id, :game_name, include_blank: true)%></td>
<% end %>
<td><span class="remove">Remove</span></td>
</tr>
我无法想象出现了什么问题,我已经三次检查语法,拼写,逗号等,以及重新启动我的redis服务器和rails服务器作为一个解决方案建议。
答案 0 :(得分:1)
您必须将变量放在本地键中:
<%= render 'tournaments/form_partials/standing_fields', locals: {f: standings, sub: sub} %>