观点:
<%= form_tag :controller => 'hotels',:search=>params[:search] do %>
<%= text_field_tag :search, nil, :class => 'search-box', :required => true,:placeholder=>'Type Your City Name(Bhubaneswar,Cuttack)'%>
<%= submit_tag "Search", :name=>'btnsearch',class: "btn-orange",:method=>'get' %>
<%end%>
在控制器中:
@hotels= Hotel.where('hotel_location LIKE ?',"%#{params[:search]}%").includes(:offers)
搜索工作正常,但问题是,当我再次加载页面时,它显示数据库中的所有值,过滤器不起作用。
我认为我可以通过将params[:search]
传递给网址解决此问题,但我不知道该怎么做。
答案 0 :(得分:0)
将:method => 'get'
从submit_tag
移至form_tag
行:
<%= form_tag :controller => 'hotels',:search=>params[:search], method: :get do %>
答案 1 :(得分:0)
试试这个: -
<%= form_tag :controller => 'hotels', :action => "action_name", method: :get do %>
<%= text_field_tag :search, params[:search], :class => 'search-box', :required => true,:placeholder=>'Type Your City Name(Bhubaneswar,Cuttack)'%>
<%= submit_tag "Search", :name=>'btnsearch',class: "btn-orange",:method=>'get' %>
<%end%>