Reputation: 107
Hi I have a form_tag that I want to go to a certain action of the controller that I implemented:
<%= form_tag(:controller => "admins", :action => "check_in") do %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
But it doesn't work, it redirects to admins/check_in a correct route thai is the one I want to redirect but rails puts "No route matches "/admins/check_in"" error. I don't understand, because this route is correct if I put in the browser "http://localhost:3000/admins/check_in" it works. How can I correct it to redirect admins controller check_in action??
Upvotes: 1
Views: 1242
Reputation: 1130
I think this is a case of using GET for the route and POST upon form submission.
If you run rake routes
you should see the route is a GET, right? When a form submits it makes a POST request. Either make the form_tag like this:
form_tag({:controller => "admins", :action => "check_in"}, :method => "get")
or change the route to POST in the routes.rb file like so:
post "admins/check_in" => "admins#check_in"
You can see, when you start rails with rails s
in the terminal, what kind of request it receives by reading the request log as it comes in.
Hope that helps, otherwise:
Upvotes: 2