我在我的应用程序(图书类)中添加了一个搜索功能,该功能已经设计并创建了视图的部分内容:
<%= form_tag url_for(:controller => 'books', :action => 'search'), :method => 'get' do %>
<label>Search</label>
<%= text_field_tag :search, params[:search], :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<% end %>
我还修改了我的routes.rb:
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
resources :users
resources :reviews
resources :books
root :to => "books#index"
match '/search', to: 'books#search', via: :get
现在,当我点击搜索按钮时,出现以下错误:
No route matches {:action=>"search", :controller=>"devise/books"}
提取的来源(第1行):
1 <%= form_tag url_for(:controller => 'books', :action => 'search'), :method => 'get' do %>
不确定为什么rails在这里寻找一个名为devise / books的控制器。任何帮助表示赞赏和感谢。
斯拉夫科
答案 0 :(得分:0)
试
match 'search', to: 'books#search', via: :get
(“/ search”中没有“/”)
答案 1 :(得分:0)
请试试这个
<%= form_tag("/search", method: "get") do %>
<label>Search</label>
<%= text_field_tag :search, :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<% end %>