How to edit a record in the List, using Ajax?


After generating code of Scaffold. I am able to see the code for
List/Edit/Delete/Show operations.

Now, I want to modify the code such a way that: I can edit a record,
there itself, without taking me to a new page.

  1. link_to_remote: is not useful as edit requires form submition.
  2. form_remote_tag: is feasible but, List requires a loop to run and
    text_field doesn’t work in a loop.

Also, each record has to be considered as a seperate “div” tag, but List
uses a loop, How to generate so many div’s dynamically?

Please suggest me, if there is any other alternative to do this.

Thanks and Regards,

1)in the list, change the Link “edit” to a link_to_remote calling the
edit action,
2) add a div to the list.rhtml below the content loop and give it the
3) in the edit action, use respond_to to check if this is an ajax call:

#somewhere in the edit action the post to edit will be received …
@post = Post.find(params[:id])

respond_to do |request|
request.rjs {
render :update { |page| page.replace_html
:“ajaxform”,:partial => ‘form’ }

this code will surely not work out of the box, i think you still have
to add the submit button, using
page.insert_html :bottom, ‘ajaxform’, ‘<input type=“submit”

or something like that… play around with it.

Hi Thorsten,

Thats a good idea. It works, I guess. Thank you.

Any other ideas, from others.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs