简体   繁体   中英

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:

<%= 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:

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 <%= form_tag url_for(:controller => 'books', :action => 'search'), :method => 'get' do %>

Not sure why rails is looking for a controller called devise/books here. 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 %> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM