SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast thebasti's Avatar
    Join Date
    Aug 2004
    Novi Sad, Serbia
    0 Post(s)
    0 Thread(s)

    [rails] Redirecting problem with grouped controllers


    I have all my admin related controllers grouped under Admin (for example I have Admin::LoginController and Admin::CategoryController). When someone tries to access a protected controller he's redirected to login page and the page he requested is saved in session like this:

    session[:goto] = request.parameters
    Now, that's all fine the problem arises after a successful login when I try to redirect user back to the original page he requested. I basically do something like (I also unset the session var and couple other things, but that's not important here):

    redirect_to session[:goto]
    Problem is that user is redirected to /admin/admin/category instead of to /admin/category. This is happening because Login controller is already in /admin and request.parameters hash :controller value has a 'admin/category' - and when redirect_to is called it uses a relative path and redirects user to /admin/admin/category.

    The trivial solution for this problem is to change :controller value to an absolute path (i.e. '/admin/category') or to remove 'admin/' altogether, but that seems messy and also I am not quite sure how it would work if Rails app is not deployed in server root.

    Does anyone knows any other way to do this?
    "Strategy without tactics is the slowest route to victory.
    Tactics without strategy is the noise before defeat."
    - Sun Tzu
    Icebergist - a web dev blog | Orange Iceberg Web App Development

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    in transition
    1 Post(s)
    1 Thread(s)
    The best way: Don't use namespaced controllers, use routing rules to add an /admin prefix to your non-namespaced controllers, and use regular :controller/:action/:whatever rules without worry since routes.rb will take care of it for you.

    The way you might have to do it now because changing your app will take too long: Set the :controller value to '/admin/category'.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts