简体   繁体   English

没有路线符合{:action =>“ search”,:controller =>“ devise / books”}

[英]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.

相关问题 没有路由匹配{:action =&gt;“ search”,:controller =&gt;“ devise / index”} - No route matches {:action=>“search”, :controller=>“devise/index”} 没有路线符合{:controller =&gt;“ devise / home”,:action =&gt;“ students”} - No route matches {:controller=>“devise/home”, :action=>“students”} 没有路线匹配{:controller =&gt;“ devise / dokumente”} - No route matches {:controller=>“devise/dokumente”} 设计命名空间 - ActionController :: RoutingError(无路由匹配{:action =>“new”,:controller =>“devise / sessions”}) - Devise in namespace - ActionController::RoutingError (No route matches {:action=>“new”, :controller=>“devise/sessions”}) 加载部分时出现奇怪的设计路由错误“没有路由匹配{:controller =&gt;“ devise / home”,:action =&gt;“ lng”,:locale =&gt;“ en”}“ - strange devise routing error on loading partial “ No route matches {:controller=>”devise/home“, :action=>”lng“, :locale=>”en“} ” 没有路由匹配{:action =&gt;“ show”,:controller =&gt;“”}} - No route matches {:action=>“show”, :controller=>“”} Rails没有路由匹配{:controller =&gt;“devise / products”} - Rails No route matches {:controller=>“devise/products”} Rails设计路由错误 - “无路由匹配”(controller =&gt;“devise / sessions”) - Rails Devise routing error - “No route matches” (controller=>“devise/sessions”) 生产服务器上出现Devise 404错误,没有路由匹配{:controller =&gt;“ devise / home”} - Devise 404 errors on production server, No route matches {:controller=>“devise/home”} 没有路线匹配{:action =&gt;“ update”,:controller =&gt;“”-Rails 5 - No route matches {:action=>“update”, :controller=>“” - Rails 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM