Rails: submit child model in nested form -
i've researched while on topic haven't found real solution trying achieve.
i'm working nested one-to-many nested form (project has many tasks). , each task has many attributes, e.g. type, assigned_individual, due_date, etc. got no problem having parent project , nested child model tasks saved/updated on 1 submit. need achieve seems opposite of effort. need 1 ajax save call each task besides global submit. when task list gets long, users don't have worry losing have written earlier other tasks. can click save button , get's feedback saying has entered task has been saved.
currently project in form_for wrapper, , tasks in fields_for partial these simplified version of have right now. here form in edit.html.erb
<%= form_for @project |f| %> <p>f.text_field :title</p> <p>f.text_field :author</p> <%= render :partial=> 'tasks', :collection=> @project.tasks %> <%= f.submit 'submit' %> <% end %>
here tasks partial:
<%= fields_for :tasks |f| %> <label>category</label> <%= f.text_field :category%> <label>description</label> <%= f.text_field :description%> <label>author</label> <%= f.text_field :author%> <label>assigned individual</label> <%= f.text_field :assigned_individual%> <label>notes</label> <%= f.text_area :notes%> <label>due date</label> <%= f.text_field :due_date%> <button onclick='update_task();'>save task</button> <% end %>
since cannot have multiple submit button in 1 form, can think of right use jquery collect every single user entry in partial , pass them big hash task controller update method.
update_task()
but there cleaner way?
Comments
Post a Comment