I am pretty new to ror...
I create a table filled thanks to a partial with a collection.
Each line is a "form_for" ending with a submit which update some
values for a specific row.
My problem is that I would like, after clicking on the submit button
that, the concerned row and only this one updates and not the whole
table. With the following code, it update well, but at the end at only
view the modified row (loosing application layout, table view...)
Can someone help me ?
I have the following views :
--------- views/home/index.html.erb
<% content_for :content do %>
<h1><%= @group.name %></h1>
<table>
<!-- Headers -->
<tr>
<th>Cars</th>
<% @group.checks.each do |c| %>
<th><%= c.name %></th>
<% end %>
</tr>
I am pretty new to ror...
I create a table filled thanks to a partial with a collection.
Each line is a "form_for" ending with a submit which update some
values for a specific row.
My problem is that I would like, after clicking on the submit button
that, the concerned row and only this one updates and not the whole
table. With the following code, it update well, but at the end at only
view the modified row (loosing application layout, table view...)
Can someone help me ?
You should submit that row using AJAX, and get the result to update that row.
You have a few possible ways to do this. you should check the
button_to_remote doc and you Javascript framework doc to implement a
unobstrusive solution.
Basically, the procedure is that, you submit your fields, via AJAX,
and update the right row with the result.
Thanks, you send me on the right way. This is how I resolve it thanks to
Ajax :
--------- views/home/_car.html.erb
<tr id='car_' + <%= car.id.to_s %> >
<% remote_form_for car do |f| %>
<td><%= car.name %></td>
<% car.group.checks.each do |c| %>
<td><%= text_field_tag 'check_' + c.id.to_s, car.check_at(c.id), :size
=> 1 %></td>
<% end %>
<td>
<%= submit_to_remote 'update_btn', 'Update',
:url => { :action => 'update_car_checks', :id => car.id },
:update => 'car_' + car.id.to_s
%>
</td>
<%end%>
</tr>
I think a form tag is not allowed to enclose a row, it must include
the whole table or fit inside a cell. Copy the generated html and
paste it into the w3c html validator web page to check.