0

This has been asked many times, but after trying all the solutions that I can find, I'm no closer towards a solution of my own.

I have a partial, _form - here's the relevant part:

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

In the marked line, I'm attempting to pass two variables to the given partial - f: standings and sub: sub. If I pass only f: standings, the page loads fine, but when I add sub: sub, I get the following error:

undefined local variable or method `sub'

which is referencing the following marked line in the _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>

I can't think of what's going wrong, I've triple checked the syntax, spelling, commas, etc as well as restarting my redis server and the rails server as one solution suggested.

dax
  • 10,779
  • 8
  • 51
  • 86

1 Answers1

1

You have to put the variables in a locals key:

<%= render 'tournaments/form_partials/standing_fields', locals: {f: standings, sub: sub} %>
Erez Rabih
  • 15,562
  • 3
  • 47
  • 64
  • that's not it - there must be something else that's triggering this because if i comment out the line in question in `_form`, i'm still getting the error. Anyway - why `locals` key? I've submitted more than one variable to a partial without it in other contexts and it's worked okay..? – dax Oct 15 '13 at 12:15
  • found the error, it was a whole different wacky thing - although your answer was correct for the question i asked. if you know about the necessity of the locals key, please let me know! – dax Oct 15 '13 at 12:31