How does ': remote => true' work in rails?

I do not understand how :remote => true works in rails. I know that when I write this, an ajax request is sent and the .js response is done. But how does it work? I mean, where is the action moving, etc.?

+13
ruby-on-rails
source share
2 answers

Let me explain the whole stream of AJAX-Rails and remote=> true .

First, when you add remote => true to the form, it submits or invokes the action that you defined on the form.

Here is an example:

 <%= form_tag({:controller => 'my', :action => 'my_data'},:id => 'filter_form', :remote => true) do %> #code here <%= submit_tag 'save', :name => 'commit'%> <%end%> 

Now the above code will go to the my_data action in my controller.

Here you can determine the type of response:

 def my_data #actions on data here respond_to do |format| format.js end end 

Now you need to create the " .js " file with the same name as the action:

 my_data.js.erb 

This " .js " file will handle the form. You can write and update document elements through jQuery and JavaScript.

+18
source share
0
source share