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>

And that's all !


2009/10/23 Leonardo Mateo <[email protected]>

>
> On Fri, Oct 23, 2009 at 4:46 PM, Alex2101 <[email protected]> wrote:
> >
> > 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.
>
> > 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
> >
> > >
> >
>
>
>
> --
> Leonardo Mateo.
> There's no place like ~
>
> >
>


-- 
Cordialement,
Alexandre Petitjean

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to