Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5.1.2 - form_with is not showing data-remote="true" in the html

Rails 5.1.2:

I'm trying to create an AJAX form using form_with in line with 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 produce 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 isn't data-remote="true" appearing in the HTML, as the first link I have posted indicates it should, and how do I get it to appear?

like image 504
Vorpulus Lyphane Avatar asked Jul 20 '17 17:07

Vorpulus Lyphane


2 Answers

I was having the same problem with a Rails 5.1.4 app. Using local: false fixed the problem.

<%= form_with url: '/', local: false do |f| %>
<% end %>
like image 200
cbrecabarren Avatar answered Nov 11 '22 13:11

cbrecabarren


Default value for data-remote is configured by option Rails.application.config.action_view.form_with_generates_remote_forms. By default in Rails 5 this option is true. Search this through all your project, it seems that you migrated from Rails 4 or smth. else with overriding this option.

like image 9
ALev Avatar answered Nov 11 '22 14:11

ALev