Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learn jQuery and AJAX for Rails

I need a good resource to get started with AJAX on Rails, where everything is explained from ground-up, in detail. Please suggest.

like image 928
rookieRailer Avatar asked Aug 04 '11 16:08

rookieRailer


People also ask

How use jQuery AJAX in Rails?

2.1 Use the jquery-rails gem Now you can make your AJAX call in the usual way: $. ajax({ type: "POST", url: "/things", data: mydata, success: function(data, textStatus, jqXHR){...}, error: function(jqXHR, textStatus, errorThrown){...} })

Is AJAX better than jQuery?

While JQuery is a library for better client-side web page development, AJAX is a technique of doing XMLHttpRequest to the server from the web page and sending/retrieving data used on a web page. AJAX can change data without reloading the web page. In other words, it implements partial server requests.

Does Rails come with jQuery?

Starting Rails 5.1, jQuery is not included by default. Let's add it on the Gemfile. To include the jQuery files in our application, we will require a few files on app/assets/javascripts/application. js .

How does AJAX call work in Rails?

Ajax enables you to retrieve data for a web page without having to refresh the contents of the entire page. In the basic web architecture, the user clicks a link or submits a form. The form is submitted to the server, which then sends back a response. The response is then displayed for the user on a new page.


1 Answers

Read this blogpost on Unobtrusive JavaScript in Rails 3 as a good starting point. However, I personally prefer writing my own Javascript and AJAX methods instead of relying on Rails helpers to do it for me, since that gives me finer control over what I intend to do.

like image 191
Gaurav Gupta Avatar answered Oct 12 '22 07:10

Gaurav Gupta