views:

33

answers:

1

I have a form that has a nested form like this:

<%- for subscription in @task.subscriptions -%>
    <%- semantic_fields_for "task[subscription_attributes][]", subscription  do |subscription_form|%>
        <%- subscription_form.inputs do -%>
            <%= subscription_form.input :workhours, :label => subscription.user.full_name%>
        <%- end -%>
    <%- end -%>
<%- end -%>

And on the task model I have:

  accepts_nested_attributes_for :subscriptions
  attr_accessible :mission_id, :statuscode_id, :name, :objectives, :start_at , :end_at, :hours, :testimony ,:subscriptions_attributes

In the form (view) I get the correct values on the workhours fields. But when I change the values and hit the submit button, the values are never changed. I can't figure out why...

I see in the console that this is building up on the tasks attributes. So the values are passing to the controller.

"subscription_attributes"=>{"11"=>{"workhours"=>"20"}, "12"=>{"workhours"=>"303"}, "9"=>{"workhours"=>"120"}, "10"=>{"workhours"=>"10"}}

On the tasks_controller I have:

@task.update_attributes(params[:task])
A: 

From the examples given on the NestedAttributes api page, I would think your subscription_attributes update should look more like this

"subscription_attributes" => [ {"id" => "11", "workhours"=>"20"}, {"id" => "12", "workhours"=>"303"}, {"id" => "9", "workhours"=>"120"}, {"id" => "10", "workhours"=>"10"} ]

So you might need to change up your form to pass the ids for the update.

Corey