I’m trying to create a form that will allow my users to navigate from
If you submit this form, the request generates an URL like this: /
tasks?month=7&year=2008 sent to the #index method on TasksController.
Why isn’t this recognized as a request to the #calendar action? What
am I doing wrong?
Route generation happens on the server side. The above HTML/view is
equivalent to this as far as Rails routing is concerned:
<% form_tag(tasks_path, :method => :get) do %>
<% end %>
Rails is properly generating the url for “tasks_path” and your browser
is submitting to that a GET request with whatever form elements are in
that form.
James, At the risk of being rude, the problem is that you don’t
understand how routing works.
map.calendar … would give you a calendar_path(:year, :month)
function, not task_path. If you have a task_path function, it is being
generated from a different rule.
In the request /tasks?year=2008&month=8, everything after the
question mark is just data generated from the form, and is invisible to
the routing.
To get the routing you were trying for, you would need:
<% form_tag(calendar_path(year, month), :method => :get) do %>
The problem you have is that the form tag is evaluated when the form is
generated, before it is sent to the browser. This means that the user
data can’t be used this way. To do what you want to do, you will need a
different algorithm.
Probably you want a two stage approach. Have one action that evaluates
the user data, and then redirects to the desired action.
Hope that helps,
–Will Merrell
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.