Rails form_with now defaults to non-remote forms

Veteran users of Rails would expect form_with helpers to return an HTML response, just like all the previous form helpers. However, the default option was now switched to an AJAX response.

With the latest change, it is often confusing for beginners to render out JS responses from the get-go. Fortunately with a recent PR to Rails, it has now been reverted back to rendering default HTML responses.

Before

Previously, form_with would generate a remote form by default.

<%= form_with url: tags_url do |f| %>
  <%= f.text_field :name %>
  <%= f.submit %>
<% end >

This would submit the form as an AJAX request. It is possible to change it by using the local option. Setting local to true would submit the form as an HTML request.

After

Now, all new 6.1 applications will generate non-remote forms by default. There’s also an override to control the default option for Rails forms using this configuration,

config.action_view.form_with_generates_remote_forms

This can be either set to true or false.

Need help on your Ruby on Rails or React project?

Join Our Newsletter