Nesting Controllers with RubyOnRails
The Problem
You want to have a /admin directory with a home page and a series of actions beneath that directory for categories of users (such as administrating users /admin/users or posts /admin/posts)
The Solution
You need to uses routes and change the syntax of your generate commands:
ruby script/generate scaffold User admin/user
ruby script/generate scaffold Post admin/post
Now you need the controller for your admin homepage:
ruby script/generate Controller admin/home
And finally, you’ll need to edit your config/routes.rb file to point /admin/ at /admin/home/
map.connect 'admin', :controller => "admin/home"
Other NotesKeep in mind controller paths are relative, so if you try and call a controller called ‘login’ from /admin/users, rails will go looking in /admin/login, so if its at the root, you’ll need to do syntax like: redirectto :controller => ‘/login’ (and not redirectto :controller => ‘login’) Got a better way? (Is this wrong?!)
Then tell me (using the comments in the blog post that points to this page…