Routing issue/bug?

For some reason the following form always sends me to the index action

<% form_for :league, :url => admin_leagues_url do |f| %>   ... <% end %>

If I set the :url to leagues_url (to which is also set in the routes file) I am routed properly to the create action.

Here is the rendered form: <form action="http://localhost:3000/admin/leagues&quot; method="post">   ... </form>

Here is part of my routing file: map.namespace :admin do |admin|     admin.resources :leagues end

Is this a bug or am I missing something?

Thanks for the help.

You can try out `rake routes` to see how your routes.rb is working.

Everything seems to be as expected (not sure how readable this will be):

That's not readable....

Do you find your `admin_leagues` is listed under POST and create method?

I can't find them.

Are you sure you have "admin/leagues" controller? in /app/controllers/admin/leagues_controller.rb ?

I believe that the preferred way to do this is

form_for([:admin, @league]) do |f|

Assuming your controller sets @league to either a new (in the new action) or existing (in the edit action) instance of League. This should automatically generate the right url in the admin namespace to either post or put the form depending on wheter or not @league.new_record? is true.

The only difference between the index action and the create action is whether you're doing a get (index) or post (create). You can always make sure you are using the right method by adding a :method=>xxx to the form_for.

Could it be that your original example read:

<% form_for :league, :url => admin_leagues_url do |f| %>

instead of

<% form_for :league, :url => admin_league_url do |f| %>

(Notice the difference between "admin_leagues_url" (plural) and "admin_league_url" (singular)).

--wpd

The only difference between the index action and the create action is whether you're doing a get (index) or post (create). You can always make sure you are using the right method by adding a :method=>xxx to the form_for.

Ya, I tried that, but the initial form was rendering with the method = "post" already.

Could it be that your original example read:

<% form_for :league, :url => admin_leagues_url do |f| %>

instead of

<% form_for :league, :url => admin_league_url do |f| %>

(Notice the difference between "admin_leagues_url" (plural) and "admin_league_url" (singular)).

--wpd

It is the plural version that I want for a POST.