I have Exam controller.
In routes.rb there is “resources :exams”
In controller there are REST-like generated methods.
I want to add my own method there:
def search
@exams = Exam.where("name like ?", params[:q])
end
In view file:
<%= form_tag(search_path, :method => "post") do %>
<%= label_tag(:q, "Szukaj: ") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Szukaj") %>
<% end %>
I know, there is no results presentation yet, it doesn’t work at all at this moment (:
When i go to http://localhost:3000/exams/search it’s mapping it to show controller and search is a :id paramether then…
How to get http://localhost:3000/exams/search to run the seach controller?
You forgot to add route. Put this in
routes.rb, beforeresources :examsNote, that
resources :examsdoesn’t generate routes for all public methods of the controller, it generates very specific set of routes. You can find more information in the rails routing guide. (see section 3.2 in particular)