Reputation: 541
When trying to logout and login then showing this error but after logged in if i use the search in application layout its working fine.and why devise is searching for the following route?
{:action=>"search_result", :controller=>"devise/gadgets"}
ActionView::Template::Error (No route matches {:action=>"search_result", :controller=>"devise/gadgets", :id=>"search-form", :method=>"get"}):
gadgets/_searh.htm.erb
1: <%= form_tag(:controller => 'gadgets', :action => 'search_result', :method => "get", id: "search-form") do %>
2: <%= text_field_tag :search, params[:search], placeholder: "Search gadget" %>
3: <%= submit_tag "Search", :name => nil ,:class => "btn-small" %>
4: <% end %>
i am using devise for authentication. and when rendering the search form in application layout showing the above error
in application.html.erb, i am using the following div
<div id="search">
<%= render :partial => 'gadgets/search' %>
</div>
and my route.rb is
root :to => 'gadgets#index', :as => 'home'
resources :gadgets
get 'gadgets/index'
get 'gadgets/show'
get 'gadgets/edit'
get 'gadgets/create'
get 'gadgets/update'
#get 'gadgets/search'
#match '/search', to: '/gadgets/search_result', :via => [:get, :post]
match "/gadgets/search_result", :via => [:get, :post]
get 'gadgets/search_result'
get 'gadgets/original'
devise_for :users
resources :users
Upvotes: 0
Views: 61
Reputation: 541
I found the answer. while using devise in application.html.erb, if i use any method should use
<% if user_signed_in? %>
Upvotes: 0
Reputation: 838
Try changing your form to this:
<%= form_tag( { :controller => 'gadgets', :action => 'search_result' }, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search gadget" %>
<%= submit_tag "Search", :name => nil ,:class => "btn-small" %>
<% end %>
Both arguments for form_tag can be hashes. The first argument can also be a string. Since you're using the hash option you have to put brackets around it. Check the Rails Docs for more.
Upvotes: 0