Ruby on Rails AJAX
By default Rails ships with CoffeeScript.
Let us see an example code to make Ajax request using the jQuery library
The above code fetches data from "/test", then appends the result to the div with an id of results.
Let us see an example of performing Ajax on delete action.
Step 1 Create an application named item.
Step 2 Write the following command.
Step 3 Write migrate command.
Step 4 Update your destroy action in aap/views/itemms/index.html.erb file by writing the following code:
Step 5 Create app/views/itemms/destroy.js.erb file.
Step 6 Go to controller file at app/controllers/itemms_controller.rb and write the following code.
Step 7 Start the Rails server.
Step 8 Run it on localhost.
Create an item as shown in the following snapshot.
It will create the item as shown below.
Click on Back button.
If you will click on Destroy link, a popup will be shown through AJAX. It will destroy this item from the list.
Click OK to delete the item finally.
DownloadDownload this example