iTranslated by AI
[Memo] Was it remote: true or local: true?
As titled. I'm summarizing this here because I was suddenly asked and found myself at a loss for an answer.
What are the remote and local options in the first place?
The remote option is used with form_for and form_tag. By specifying remote: true, you can send requests via Ajax communication.
Specifying: remote: true in the options hash creates a form that will allow > the unobtrusive JavaScript drivers to modify its behavior.
When remote: true is specified, a form is created where an unobtrusive JavaScript driver modifies its behavior.
:remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behavior. By default this behavior is an ajax submit.
:remote - If set to true, it allows the unobtrusive JavaScript drivers to control the communication behavior. By default, this behavior is an Ajax submission.
On the other hand, the local option is used with form_with. By specifying local: true, you can send requests via HTTP communication.
:local - Whether to use standard HTTP form submission. When set to true, the form is submitted via standard HTTP. When set to false, the form is submitted as a “remote form”, which is handled by Rails UJS as an XHR.
Specifies whether to use standard HTTP form submission. When set to true, the form is submitted via standard HTTP. When set to false, the form is submitted as a "remote form", which is handled by Rails UJS as an XHR.
It is quite confusing at this point, but basically, since form_with has been recommended since Rails 5.1, you probably only need to remember local: true.
Or so I thought, but there seem to be differences depending on the version
In Rails 6.0, 5.2, and 5.1, the default behavior is to return an Ajax response. However, from Rails 6.1 onwards, it now generates forms without remote by default.
You need to check the version of Rails you are using carefully when writing the code.
Discussion