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.

Not routing to correct non-default controller

#6594

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.

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

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

Activity

  1. Andrew White
    Andrew White
    • 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'
      end
    end
    

    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 http://127.0.0.1:3000/articles/1/front_page_articles/new
    {"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.

    March 19th, 2011 @ 05:38 AM

  2. mikemaltese
    mikemaltese

    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.

    March 27th, 2011 @ 06:06 PM

  3. Andrew White
    Andrew White
    • State changed from needs-more-info to invalid

    Okay, thanks for the update.

    March 27th, 2011 @ 06:12 PM