[英]No route matches {:action=>“search”, :controller=>“devise/books”}
I have added a search function to my application (books class) which already has devise and created a partial for the view: 我向已经设计好的应用程序(books类)添加了搜索功能,并为视图创建了一部分:
<%= 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 %>
I also modified my routes.rb accordingly: 我还相应地修改了route.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
Now when I hit the search button I get the following error: 现在,当我按下搜索按钮时,出现以下错误:
No route matches {:action=>"search", :controller=>"devise/books"}
Extracted source (around line #1): 提取的源(第1行附近):
1 <%= form_tag url_for(:controller => 'books', :action => 'search'), :method => 'get' do %>
Not sure why rails is looking for a controller called devise/books here. 不知道为什么Rails在这里寻找一个叫做devise / books的控制器。 Any help appreciated and thanks in advance. 任何帮助表示赞赏,并在此先感谢。
Slavko 斯拉夫科
try 尝试
match 'search', to: 'books#search', via: :get
(No "/" in "/search") (“ /搜索”中没有“ /”)
please try this 请尝试这个
<%= form_tag("/search", method: "get") do %>
<label>Search</label>
<%= text_field_tag :search, :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.