I'm trying to implement a simple search function for my Rails app by following this guide. I am trying to allow users to search for animal by name.
Here's my current code:
controllers/animals_controller.rb
class AnimalsController < ApplicationController
def search
@animal = Animal.search(params[:search])
end
end
Here's my views/animals/index.html.erb
<%= form_tag :controller => 'animals', :action => 'search', :method => 'get' do %>
<%= text_field_tag :search, params[:search], :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<% end %>
And here is the error I keep getting:
No route matches {:action=>"search", :controller=>"animals", :method=>"get"}
I don't understand why this isn't working. I have the search function defined in the animal_controller.rb. Can anyone point out why the search function may not be working?
Based on the guide you are following, creating a
GET /searchroute was never mentioned. You can define the route inconfig/route.rbwith thisor