Help with routing
I have a my admin controllers in a folder named admin in my controller folder. It looks something like this:
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:
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.
:controller => "authorize",
:action => "authenticate"
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.
I'd definitely use a before_filter to check for authentication but to route to something like that you do this:
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:
map.connect '/admin', :controller => 'admin/authorize', :action => 'authenticate'
http://domains.com/admin/admin/controller then to /admin/admin/admin. So remember the leading slash.
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.
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
But that's just me.