Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Incorrect routing when controller specified for resources - Rails 3.0.0.rc

#5458

Problem 1

  resources 'account', :controller => 'users', :as => 'users' do
    collection do
      post 'reward_all'
    end

    member do
      post 'reward'
    end
  end

yields the error: "missing :action" - referring the apparent need to specify an action for post 'reward'. This seems redundant, as I would change it to

  post 'reward' => :reward

Problem 2

  resources 'account', :controller => 'users', :as => 'users' do
    collection do
      post 'reward_all'
    end

    member do
      post 'reward' => :reward
    end
  end

yields the following - note the incorrect controller and route name on the reward_all collection route
Also, no default named route is provided for the member action

account_reward_all POST   /account/reward_all         {:controller=>"account", :action=>"reward_all"}
                   POST   /account/:id/reward         {:controller=>"users", :action=>"reward"}
                   GET    /account(.:format)          {:controller=>"users", :action=>"index"}
             users POST   /account(.:format)          {:controller=>"users", :action=>"create"}
          new_user GET    /account/new(.:format)      {:controller=>"users", :action=>"new"}
                   GET    /account/:id(.:format)      {:controller=>"users", :action=>"show"}
                   PUT    /account/:id(.:format)      {:controller=>"users", :action=>"update"}
              user DELETE /account/:id(.:format)      {:controller=>"users", :action=>"destroy"}
         edit_user GET    /account/:id/edit(.:format) {:controller=>"users", :action=>"edit"}

Even stranger, by specifying an action on the collection route, it corrects the controller:

  resources 'account', :controller => 'users', :as => 'users' do
    collection do
      post 'reward_all' => :reward_all
    end

    member do
      post 'reward' => :reward, :as => 'reward'
    end
  end

yields

account_reward_all POST   /account/reward_all         {:controller=>"users", :action=>"reward_all"}
       reward_user POST   /account/:id/reward         {:controller=>"users", :action=>"reward"}
                   GET    /account(.:format)          {:controller=>"users", :action=>"index"}
             users POST   /account(.:format)          {:controller=>"users", :action=>"create"}
          new_user GET    /account/new(.:format)      {:controller=>"users", :action=>"new"}
                   GET    /account/:id(.:format)      {:controller=>"users", :action=>"show"}
                   PUT    /account/:id(.:format)      {:controller=>"users", :action=>"update"}
              user DELETE /account/:id(.:format)      {:controller=>"users", :action=>"destroy"}
         edit_user GET    /account/:id/edit(.:format) {:controller=>"users", :action=>"edit"}

Note that the named route is still wrong, but only for the collection action

Reported by Jamie Wong · August 25th, 2010 @ 05:58 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Jamie Wong
    Jamie Wong

    Also, if I change the post collection line to

        post 'reward_all' => :reward_all, :as => 'reward_all'
    

    It corrects the named route.

    Why are these things not the defaults?

    August 25th, 2010 @ 06:13 PM

  2. Andrew White
    Andrew White
    • State changed from new to invalid
    • Importance changed from to Low

    Using your original routes, here's the output from the current master:

    reward_all_users POST   /account/reward_all(.:format) {:action=>"reward_all", :controller=>"users"}
         reward_user POST   /account/:id/reward(.:format) {:action=>"reward", :controller=>"users"}
                     GET    /account(.:format)            {:action=>"index", :controller=>"users"}
               users POST   /account(.:format)            {:action=>"create", :controller=>"users"}
            new_user GET    /account/new(.:format)        {:action=>"new", :controller=>"users"}
           edit_user GET    /account/:id/edit(.:format)   {:action=>"edit", :controller=>"users"}
                     GET    /account/:id(.:format)        {:action=>"show", :controller=>"users"}
                     PUT    /account/:id(.:format)        {:action=>"update", :controller=>"users"}
                user DELETE /account/:id(.:format)        {:action=>"destroy", :controller=>"users"}
    

    There were some differences between symbols and strings which hopefully have now been rectified. If you'd used symbols you'd get the same output in RC2.

    August 25th, 2010 @ 09:42 PM