1

What do 'remote: true' does in a rails form_for/link_to? In which case I may use it?

3 Answers3

1

This will add a part to your form, data-remote="true", that will cause the form to be submitted by Ajax rather than by the browser's normal submit mechanism.

DustinFisher
  • 396
  • 2
  • 11
1

Checking Rails documentation:

:remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behavior. By default this behavior is an ajax submit.

This quote already answers the first half of your question. Googling further for Unobtrusive Javascript gives you, among other things,

all of which will explain in detail the whys and wherefores of UJS.

Finally, googling for Rails and Unobtrusive Javascript gives you the library Rails uses, and its documentation, so you can check exactly what is happening.

Community
  • 1
  • 1
Amadan
  • 191,408
  • 23
  • 240
  • 301
1

It's a bind for the Rails UJS (Rails unobtrusive javascript) remote hook.

It basically creates an ajax "link" for when you include remote on a link_to,button_to or form:

<%= link_to   "Text", your_path, remote: true %>
<%= button_to "Text", your_path, remote: true %>
<%= form_tag your_path, remote: true do |f| %>
   ...
<% end %>

The above shows how you'd use it.

It's essentially a way to send an "ajax" request to your backend (so you can change your page without refreshing). There's a good Railscast about it here.

Richard Peck
  • 76,116
  • 9
  • 93
  • 147