Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

RoR and Ajax

 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

State/County<select id="state">
<option>California</option>
<option>Dallas</option>
</select>

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 ]
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karthik Guru:
Request some inputs on the way RoR does Ajax.


This article at ONLamp.com might be a good start.

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?


Yes, it uses "innerHTML" as far as I can tell.

Originally posted by Karthik Guru:
What javascript library is the ajax support based on?


Prototype

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.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and I haven't actually used Ajax in Rails to update the contents of a non-DIV element so that snippet right there comes without a warranty
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Lasse that helps.
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic