简体   繁体   English

Rails Bootstrap-从“提交”按钮中删除“名称”属性

[英]Rails Bootstrap - Remove name attribute from submit button

I have the following search form I made: 我有以下搜索表格:

          <%= bootstrap_form_for :search, url: admin_panel_users_path, method: 'get' do |f| %>
              <div class="row" style="margin-top: 15px; line-height: 25px;">
                <div class="col-md-2 text-center" style="margin-top: 6px; font-weight: bold">
                  <%= f.label :keyword%>
                </div>
                <div class="col-md-8">
                  <%= f.text_field :keyword, hide_label: true %>
                </div>
                <div class="col-md-2">
                  <%= f.submit 'Search User', hide_attribute_name: true, class: 'btn btn-success' %>
                </div>
              </div>
          <% end %>

However, when I submit, I get a lot of things that I don't need as parameters in my url, and the url then looks like this: 但是,当我提交时,我得到了很多我不需要的东西作为url中的参数,然后url看起来像这样:

?utf8=✓&search%5Bkeyword%5D=&commit=Search+User

While I only want the url to be like this: 虽然我只希望网址是这样的:

?keyword=mysearch

Is there a way to do it with the bootstrap gem ? 有没有办法使用bootstrap gem And in addition, remove that hidden UTF field it places 另外,删除它放置的隐藏的UTF字段

Pass enforce_utf8 with form as false. 传递带有形式为false的enforce_utf8 It was added in Rails 3 originally to fight IE compatibility issues for a form submitted with GET request. 它最初是在Rails 3中添加的,目的是解决GET请求提交的表单的IE兼容性问题。 It is called as _snowman param. 它称为_snowman参数。

:enforce_utf8 - If set to false, a hidden input with name utf8 is not output. :enforce_utf8-如果设置为false,则不会输出名称为utf8的隐藏输入。

For removing commit parameter, pass submit_tag with name:nil 要删除提交参数,请使用name:nil传递submit_tag

<%= f.submit 'Search User', name: nil, hide_attribute_name: true, class: 'btn btn-success' %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM