1

My starting place was this discussion: Syntax for form_for when building an array from checkboxes

I have a call to my model passing back an array of valid options. This array then makes a series of check_box_tag

<%= form_for @game, :url => wizard_path do |f| %>

  <div>
  <% @game.select_races.each do |a| %>
    <%= f.label a %>
    <%= check_box_tag 'game[races][]', a , true %>
  <% end %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

This successfully creates an array called 'races' containing the desired output. The problem is that it doesn't actually update the races attribute. So my races attribute is still nil.

I'm sure this is a painful Rails beginner question. Any help is appreciated.

UPDATE

My allowed params were:

def game_params
  params.require(:game).permit(:shattered_empire, :shards_of_the_throne, :number_of_players, :rules, :strategy_cards, :players, :races)
end

Which needed to be updated to:

def game_params
  params.require(:game).permit(:shattered_empire, :shards_of_the_throne, :number_of_players, :rules, :strategy_cards, :players, {:races => []})
end
2
  • 1
    Have you permitted this attribute in the controller? Commented Apr 17, 2015 at 17:53
  • 1
    Note that when a param is an array (as this will be) you have to explicitly do :races => [] in your .permit() call. Commented Apr 17, 2015 at 18:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.