Set local: true to default for form_with in Rails 5

I am working on a project where we will not use ajax calls to submit forms, so I need to put local: truein each form of the project, as indicated in the docs rails :

:local - By default form submits are remote and unobstrusive XHRs. Disable remote submits with local: true.

Is it possible to set the default local parameter by default?

We use the Rails 5 helper form_withas follows:

<%= form_with(model: @user, local: true) do |f| %>
    <div>
        <%= f.label :name %>
        <%= f.text_field :name %>
    </div>

    <div>
        <%= f.label :email %>
        <%= f.email_field :email %>
    </div>
    <%= f.submit %>
<% end %>
+4
source share
1 answer

Consider overriding a method form_with:

# form_helper.rb
def form_with(options)
  options[:local] = true
  super options
end

This should solve it for each form in your application.

+1
source

Source: https://habr.com/ru/post/1690815/


All Articles