Monday, 12 August 2013

Failing to store nested attributes values for models in rails (rails recipes 36)

Failing to store nested attributes values for models in rails (rails
recipes 36)

I am trying to store the value for each level i add, the number of fields
visible gets updated as they should when i use add/remove buttons, but
when i press submit only the game name gets stored. The scores are
discarded somehow.
<h1>Editing game</h1>
<% flash.each do |name, msg| -%>
<%= content_tag :div, msg, class: name %>
<% end -%>
<!--START-->
<%= form_for @game do |f| %>
<%= f.label :name %> <%= f.text_field :name %>
<h3>Scores:</h3>
<%= f.fields_for(:levels) do |level_form| %>
<!--<%= level_form.label :score %>-->
<%= level_form.text_field :score %>
</br>
<% end %>
<%= f.submit %>
<% end %>
<!--END-->
<%= button_to "Add Level",
:action => 'add_level',
:id =>@game
%>
<%= button_to "Remove Level",
:action => 'remove_level',
:id =>@game
%>
<%= link_to 'Show', @game %> |
<%= link_to 'Back', games_path %>

No comments:

Post a Comment