Many programmer uses jquery to catch click event and do $.get or $.post to access the server and print the response in a required div.
But there is a handy way to do ajax request using UJS provided by Rails .
Let us take an example of
add to wish list event.
This can be easily achieved in three easy steps. Now lets see how to do that in rails using UJS
show.haml.html) your may have
Now we make it as ajax request by adding
:remote => true
Now in controller
1 2 3 4 5 6
Now create a file named wish_list.js.erb
1 2 3 4 5
You can use jquery to show the loading part while server is responding
1 2 3
That’s it. As simple as that.