On May 24, 2010, at 11:38 AM, Ralph Shnelvar wrote:
> 
>> Or skip the RJS and just write JavaScript.  I tend to think that RJS is 
>> one of the more pointless features of Rails...
>> 
>> Best,
>> --
>> Marnen Laibow-Koser
>> http://www.marnen.org
>> [email protected]
> 
> Which is exactly what I have been trying to do!
> 
> But I _still_ can't find a decent tutorial that explains how to send an 
> XHR request to a RoR app and what to do on the server side to process 
> the request.


Ralph, you are looking for two different kinds of knowledge:

1. How to send an XMLHttpRequest. This is a jQuery question. The answer is 
usually jQuery.post or jQuery.ajax. You will have to include your 
authentication token in the post request if you are protecting against forgery.

2. How Rails responds to the XMLHttpRequest. This is simply handled by a 
controller action. Use something like if xhr? to make sure you are responding 
to an XMLHttpRequest if that's important to you.

3. How to render a response that you can then use to change the page. This is 
simply whatever you put in the response body. As someone previously noted, JSON 
may be easier and more flexible to use than XML. Then couple this with the 
success() callback in your jQuery .post or .ajax to change your DOM 
appropriately.

This is not a cookbook solution, as all such applications are different. 
Hopefully, it's a starting point for your research and you'll find it easy to 
join Rails and jQuery.

Steve

-- 
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