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.

Redirect broken when using namespaces in routes.rb

#4389

In order to be redirected to /admin/dashboard from /admin I defined the following routes:

namespace :admin do
  match "/", :to => redirect("/admin/dashboard")
  match "/dashboard", :to => "dashboard#index", :as => :dashboard
end

It results in: "ActionController::RoutingError (uninitialized constant Admin::Controller):"

Different one works as expected:

match "/admin", :to => redirect("/admin/dashboard")
namespace :admin do
  match "/dashboard", :to => "dashboard#index", :as => :dashboard
end

But I can't relax, it seems something wrong in the router internals, right?

Reported by wildchild · April 14th, 2010 @ 03:14 AM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Ryan Bigg
    Ryan Bigg

    Could you please submit a failing test for this?

    April 14th, 2010 @ 04:13 AM

  2. wildchild
  3. Tyler Hunt
    Tyler Hunt

    This also fails with the same error when using #root:

    namespace :admin do
      root :to => redirect('/admin/companies')
      resources :companies
    end
    

    June 22nd, 2010 @ 04:19 PM

  4. Andrew White
    Andrew White

    Attached patch fixes this issue.

    I've written it so that the redirect path is namespaced which seems logical to me:

    namespace :admin do
      root :to => redirect('/companies')
      resources :companies
    end
    

    If you don't want it this way then let me know and I'll change the patch.

    June 24th, 2010 @ 10:55 AM

  5. Damien MATHIEU
    Damien MATHIEU

    If the redirect path is namespaced, it mean we can't redirect to a path outside of the current namespace. That doesn't seem so logical to me.

    June 24th, 2010 @ 11:06 AM

  6. Andrew White
    Andrew White

    I thought about that and you'd handle that situation like this:

      match '/admin', :to => redirect('/other')
    

    To me it seems everything within a namespace block should be namespaced.

    June 24th, 2010 @ 11:16 AM

  7. Andrew White
    Andrew White
    • State changed from new to open

    Updated patch which doesn't namespace redirect path

    June 24th, 2010 @ 11:51 AM

  8. Repository