Request some inputs on the way RoR does Ajax. Please use simple example code ( not heavy duty RoR/ Ruby ). Is the response DOM constructed on the server? Does it use 'innerHTML' to render on the client? What javascript library is the ajax support based on?
Say I have a trivial dropdown
Country <select id="country"> <option>India</option> <option>USA</option> <option>UK</option> </select><br/>
and i need to update another DD based on the country you picked,
How do you indicate on the 'country' DD that you need to do something on 'onchange' meaning which method on the controller is responsible for generating the response. How is the error handling done in case of any issues in making an ajax request/getting a response etc.
How is the response constructed on the server and how does the response look like?
thanks! [ February 10, 2006: Message edited by: Karthik Guru ]
Balaji Loganathan
author and deputy
Bartender
Joined: Jul 13, 2001
Posts: 3150
posted
0
Karthik, While i understand you are looking for specific example, just thought i would post this link (http://www.rubyonrails.com/screencasts) which has link to source as well.
Originally posted by Balaji Loganathan: Karthik, While i understand you are looking for specific example, just thought i would post this link (http://www.rubyonrails.com/screencasts) which has link to source as well.
Thanks for the link. I checked out the ajax-rails presentation but i guess this is not the right pace for me. It appeared as if the presenter was in a hurry to get somewhere.
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
5
posted
0
Originally posted by Karthik Guru: Request some inputs on the way RoR does Ajax.
Originally posted by Karthik Guru: Is the response DOM constructed on the server?
Well, in general it's the raw snippet of HTML that gets constructed on the server but of course you could build that HTML snippet with some DOM library or by string concatenation--it's up to you to decide.
Originally posted by Karthik Guru: Does it use 'innerHTML' to render on the client?
Originally posted by Karthik Guru: Say I have a trivial dropdown
and i need to update another DD based on the country you picked,
How do you indicate on the 'country' DD that you need to do something on 'onchange' meaning which method on the controller is responsible for generating the response. How is the error handling done in case of any issues in making an ajax request/getting a response etc.
You could try something like this (based on an example from the ONLamp.com article):
Originally posted by Karthik Guru: How is the response constructed on the server and how does the response look like?
In the above example, the Ajax request would be handled by the "get_states_for_country" action in the "karthik_controller", which would be responsible for rendering back a fragment of HTML that the client-side JavaScript then dumps inside the element identified with ":update => :element_id", e.g.