Q: Nested form in rails does not save I am working on an app that calculates rations. Each ration has many ration_items, each ration_item belongs to a ration and a feedstuff. I want the user to update the quantities of the ration_items belonging to a ration with one submit, so I made a nested form on the edit ration page. 
The table with ration_items that belong to a particular ration looks like this:


<%= form_for @ration do |f| %>
     <table class="table table-striped">
      <thead>
        <tr>
          <th>Quantity</th>
          <th>Name</th>
        </tr>
      </thead>
      <tbody>
          <% @ration.ration_items.each do |ration_item| %>
          <%= render 'ration_item_row', feedstuff: ration_item.feedstuff, ration_item: ration_item, f: f %>
          <% end %>
      </tbody>
     </table>
<%= f.submit %>
<% end %>


The partial with the ration_item row:


<%= f.fields_for ration_item do |r| %>
    <tr>
      <td><%= r.number_field :quantity, value: ration_item.quantity %></td>
      <td><%= feedstuff.name %></td>
      <td><%= link_to "", ration_item, method: :delete, class: "glyphicon glyphicon-trash", data: { toggle:'tooltip' }, title: 'Delete', data: { confirm: 'Are you sure?' } %></td>
    </tr>
<% end %>


I added strong params in ration controller:
def ration_params
  params.require(:ration).permit(:name, :user_id, ration_items_attributes: [:id, :quantity, :feedstuff_id])
end

Now when I change a ration_item quantity and submit, it does not save the quantity, but only redirects again to the edit page. Server output is as follows: 


Started PATCH "/rations/4" for 127.0.0.1 at 2015-08-18 16:11:05 +0200
Processing by RationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"HeG3ffOcUJUY68ggiruE1pDReo8X5ftr4YBgBswGMJzQ+cOF3GlCcQHm3Kd349WTDkGzOwUtEEm2Ur9DpKGGPw==", "ration"=>{"ration_item"=>{"quantity"=>"500"}}, "commit"=>"Ration bewaren", "id"=>"4"}
  Ration Load (0.2ms)  SELECT  "rations".* FROM "rations" WHERE "rations"."id" = ? LIMIT 1  [["id", 4]]
Unpermitted parameter: ration_item
   (0.1ms)  begin transaction
   (0.1ms)  commit transaction
Redirected to http://localhost:3000/rations/4/edit
Completed 302 Found in 6ms (ActiveRecord: 0.3ms)


Any ideas on how I can get this to work highly appreciated!
ration.rb: 


class Ration < ActiveRecord::Base
  belongs_to :user
  has_many :ration_items, dependent: :destroy
  validates :name, presence: true
  validates :user_id, presence: true
  accepts_nested_attributes_for :ration_items
  
  def to_s
    name
  end
  
end


ration_item.rb:


class RationItem < ActiveRecord::Base
  belongs_to :feedstuff
  belongs_to :ration
  validates :feedstuff_id, presence: true
  validates :quantity, presence: true
end


feedstuff.rb: 


class Feedstuff < ActiveRecord::Base
  validates :user_id, presence: true
  validates :name, presence: true, length: {maximum: 20}, uniqueness: true
  belongs_to :user
  has_many :ration_items
  
  def to_s
    name
  end

    
end


