我的网址现在看起来像是:
http://146.185.xx.xx/search/?utf8=%E2%9C%93&search=the
我想这样做:
http://146.185.xx.xx/search/the
我该怎么做?
My Post.rb;
def self.search(query)
where("title like ?", "%#{query}%")
end
我的观点形式:
form action="/search/<%= params[:search] %>" method="get" class ="navbar-form navbar-right" role ="search")
<div class="form-group">
<%= text_field_tag :search, nil, placeholder: "Найти посты", :class => "form-control", :pattern=>".{3,}" %>
<%= submit_tag "OK", :name => nil, :class => "search_btn" %>
</div>
</form>
路线:get "/search" => "posts#index"
答案 0 :(得分:0)
不要使用form_tag
使用
<form action="<%= search_path %>" method="get"></form>
或者你可以设置
<%= form_tag('/search/', :method => "get", :enforce_utf8 => false %>
希望这有帮助