当我提交我的form_tag时,没有任何反应

时间:2018-04-19 16:47:14

标签: ruby-on-rails ruby forms

我目前正在尝试为与我的客户端表关联的地方实施搜索栏。

当我按下回车时,我希望我的页面选择与输入匹配的所有地方。

我的form_tag看起来像这样:

= form_tag (@client_place_path), method: :get do
  = text_field_tag :query,
  params[:query],
  placeholder: "Find a place"

我的位置控制器:

if params[:query].present?
  @places_search = Place.where("email ILIKE ?", "%#{params[:query]}%")
else 
  @places = Place.all
end

我的路线

resources :places do
  delete 'destroy_image', to: 'places#destroy_image'
  # get 'visits', to: 'visits#index'
  # delete 'visits/reset', to: 'visits#reset'
end

并且耙路线看起来像这样:

client_places GET    /client/places(.:format)                                         client/places#index
              POST   /client/places(.:format)                                         client/places#create
new_client_place GET    /client/places/new(.:format)                                     client/places#new
edit_client_place GET    /client/places/:id/edit(.:format)                                client/places#edit
client_place GET    /client/places/:id(.:format)                                     client/places#show
             PATCH  /client/places/:id(.:format)                                     client/places#update
             PUT    /client/places/:id(.:format)                                     client/places#update
             DELETE /client/places/:id(.:format)  

因此,当我尝试获取某些内容时,我的视图保持不变,但网址看起来像http://localhost:3000/client/places?utf8=%E2%9C%93&query=#{Place.name}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

if params[:query].present?
  @places_search = Place.where("email ILIKE ?", "%#{params[:query]}%")
else 
  @places = Place.all
end

良好的形式是正确的,它发送回到同一页面与get请求但是 @places搜索应该是@places 在QUERY ILIKE也应该像