Rails 5.1.2 - form_with doesn't show data-remote = "true" in html
Rails 5.1.2:
I am trying to create an AJAX form using form_with according to the Rails documentation and this GitHub thread .
This code:
<%= form_with url: '/' do |f| %>
<% end %>
and in fact this code:
<%= form_with url: '/', remote: true do |f| %>
<% end %>
both create this html:
<form action="/" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="..." />
<input type="hidden" name="authenticity_token" value="..." />
</form>
Why doesn't it appear in the HTML data-remote="true"
as the first link I posted indicates that it should and how can I display it?
source to share
In Rails 5.1.2 By default, form_with
it assumes that your form will use Ajax. You can opt out of this behavior by passing a parameter :local
to form_with
.
<%= form_with url: '/' do |f| %>
<% end %>
The above code creates
<form action="/" accept-charset="UTF-8" data-remote="true" method="post">
<input name="utf8" type="hidden" value="..." />
<input type="hidden" name="authenticity_token" value="..." />
</form>
Also if you want to use the form without ajax you can use below -
<%= form_with url: '/', local: true do |f| %>
<% end %>
source to share
This will happen in Rails 5.1
With my config in new_framework_defaults_5_1.rb like this:
# Make `form_with` generate non-remote forms.
Rails.application.config.action_view.form_with_generates_remote_forms = false
And in my view file I use like this:
= form_with(model: your_model , url: your_path, method: :post, local: false) do |f|
....your input here...
Now your html code will generate data-remote: true on your form.
source to share