This project is archived and is in readonly mode.

#6594 ✓invalid

Not routing to correct non-default controller

Reported by mikemaltese | March 18th, 2011 @ 09:04 PM

My config/routes.rb contains this:

resources :front_page, :only => [:new, :create], :controller => "articles/front_page_articles"

However, the path /articles/:id/front_page_articles/new is routed to FrontPageArticlesController, not Articles::FrontPageArticlesController as I expect. Running rake routes agrees with me that it should route to the latter.

Comments and changes to this ticket

  • Andrew White

    Andrew White March 19th, 2011 @ 05:38 AM

    • State changed from “new” to “needs-more-info”
    • Importance changed from “” to “Low”

    Need a bit more of your routes.rb file to see what's happening - to get the '/articles/:id' part of the path the resources call needs to be wrapped with something, e.g:

    resources :articles do
      member do
          resources :front_page_articles, :only => [:new, :create], :controller => 'articles/front_page_articles'

    Firstly the 'member' should be 'nested' - member is for specifying actions on the current resource not defining nested resources. If you'd used nested the path would be '/articles/:article_id', however this is irrelevant because it still works anyway. Using the above routes in a test application (Rails 3.0.5) this is what I get:

    $ curl
    {"action"=>"new", "id"=>"1", "controller"=>"articles/front_page_articles"}

    The only way I can reproduce your problem is if a controller exists at app/controllers/front_page_articles_controller.rb and not at app/controllers/articles/front_page_articles_controller.rb. Because of how AS::Dependencies works it will find a constant in the global namespace if one in the Articles namespace doesn't exist or the Articles namespace doesn't exist. Check you haven't got a typo in a path somewhere - that's probably the cause of the problem.

  • mikemaltese

    mikemaltese March 27th, 2011 @ 06:06 PM

    Hi Andrew,

    I've already moved past this issue by renaming some controllers, so my routes.rb file would be of no help. From what I remember, however, I did have controllers with the same name defined in the root scope and in the 'articles' scope, and it was routing to the root one when it shouldn't have.

  • Andrew White

    Andrew White March 27th, 2011 @ 06:12 PM

    • State changed from “needs-more-info” to “invalid”

    Okay, thanks for the update.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>