ruby-on-rails-5 – 在Rails 5中为form_with设置local:true

我正在开发一个项目,我们不会使用ajax调用来提交表单,所以我需要在项目的每个表单中放置local:true,如rails docs中所示:

:local – 默认情况下,表单提交是远程和不引人注目的XHR.使用local:true禁用远程提交.

有没有办法默认将local选项设置为true?

我们正在使用Rails 5 form_with helper,如下所示:

<%= 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 %>

解决方法

考虑重写form_with方法:
# form_helper.rb
def form_with(options)
  options[:local] = true
  super options
end

这应该为您的应用程序中的每个表单解决它.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...