Render or update only one element of a table

Hi,

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>

      <!-- Values -->
      <%= render :partial => "cars", :collection => @group.cars%>
    </table>

    <%= link_to 'Add car', new_car_path %>
<% end %>

--------- views/home/_car.html.erb
<tr>
  <% form_for car, :url => { :action => "update_car_checks" } do |f|
%>
    <td><%= car.name %></td>
    <%= hidden_field_tag :car_id, car.id %>
    <% 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><%= f.submit 'Record' %></td>
    <% end %>
</tr>

Then, in home controller :
--------- controllers/home_controller.rb
def update_car_checks
  @car = Car.find(params[:car_id])

  #... Some updates and check for the car...

  render :partial => "car"
end

Hi,

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

>

<% remote_form_for car do |f| %>

<%= [car.name](http://car.name) %>

<% car.group.checks.each do |c| %>

<%= text_field_tag 'check_' + c.id.to_s, car.check_at([c.id](http://c.id)), :size => 1 %>

<% end %>

<%= submit_to_remote ‘update_btn’, ‘Update’,

:url => { :action => ‘update_car_checks’, :id => car.id },

:update => ‘car_’ + car.id.to_s

%>

<%end%>

And that’s all !

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.

Colin