Railsでform_tagをpostからgetにするとURLにutf8のパラメータが付くあれ消したい
検索フォームpostよりgetの方がURLがわかりやすくなってよいなぁとか思ってgetにしたらURLにutf8=✓とかbutton=とか勝手にパラメータついてなんなんこれってかんじ。
結論から言うと同じことしてた人がいるみたいでこの方法で消せた。
Ruby on Rails - submit_tag で付加される commit, utf8 パラメータ! - mk-mode BLOG
config/intializers/utf8_enforcer_tag.rbとか作って以下を書いておく。
module ActionView module Helpers module FormTagHelper def utf8_enforcer_tag "".html_safe end end end end
あとbutton_tagでbutton=とかがパラメータに入るのが嫌な場合はname: nilとか書いておけば消えました。
<%= form_tag({controller: :commits, action: :search}, {method: "get", class: "form-inline"}) do %> <%= text_field_tag :keyword, @keyword, size: '50%', class: "form-control", placeholder: "keyword" %> <%= button_tag(type: "submit", name: nil, class: "btn btn-default") do %> Search <span class="glyphicon glyphicon-search" aria-hidden="true"></span> <% end %> <% end %>