Rails 4:Checkbox数组没有更新我的属性

时间:2015-04-17 17:50:14

标签: ruby-on-rails arrays

我的出发点是这个讨论:Syntax for form_for when building an array from checkboxes

我调用了我的模型传回一系列有效选项。然后该数组生成一系列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 %>

这成功创建了一个名为&#39; races&#39;包含所需的输出。问题是它实际上并没有更新races属性。所以我的种族属性仍然是零。

我确定这是一个痛苦的Rails初学者问题。任何帮助表示赞赏。

更新

我允许的参数是:

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

需要更新到:

def game_params
  params.require(:game).permit(:shattered_empire, :shards_of_the_throne, :number_of_players, :rules, :strategy_cards, :players, {:races => []})
end

0 个答案:

没有答案