SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Location
    Sweden
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with routing

    I have a my admin controllers in a folder named admin in my controller folder. It looks something like this:

    controllers/admin/authorize_controller.rb

    What I want to do is to route the following request "http://www.mypage.com/admin" to that controller, but I don't really know how to do that.

    Here is my attempt in the routes.rb file:
    PHP Code:
      map.connect '/admin',
        :
    controller => "authorize",
        :
    action => "authenticate" 
    I doesn't work and I'm not really sure on what I'm doing so if anyone knows I would really appreciate your help.

  2. #2
    SitePoint Addict SRTech's Avatar
    Join Date
    Mar 2005
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was having the same problem the other day as well, but realized that Rails does not need to have a route entry to map to the admin module correctly. (You did generate it as a Admin::authorize right?)

    Just remove the route, and try it, maybe using a before_filter to check for the authentication.

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd definitely use a before_filter to check for authentication but to route to something like that you do this:
    Code:
    map.connect '/admin', :controller => 'admin/authorize', :action => 'authenticate'
    But in this situation I don't recommend that. Also, watch out in your link_tos and url_fors to use :controller => '/admin/whatever' If you don't put the leading "/" then your URLs will soon get out of hand looking like this:

    http://domains.com/admin/admin/controller then to /admin/admin/admin. So remember the leading slash.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2005
    Location
    Sweden
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. Would be interesting hear what you recommend. Is it stupid to have folders in the controller folder? Maybe it's better to make the admin section of a page as component?

    Would be interesting to hear how you guys structure a homepage that has both a public and admin version. Do you use shared controllers or do you have on controll for:
    news (public controller)
    news_admin (admin controller)

    It feels important to start structering the page on a good way before going to far in the development.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No it's not stupid to have folders in your controller folder. I use the "admin" folder also, there is nothing wrong with it I don't think. The only thing I don't like about it is that you can't change it...

    My structure would be

    news
    admin/news

    But that's just me.


Bookmarks

Posting Permissions

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