Ana B. wrote:
Hi, im building a little cms and i want to separate the admin zone
controllers in a subfolder(controllers/admin) if possible to all be
managed by one login module, i just have managed simple 3 or 4
controller apps so any help you can give me will be very apreciated.
I have a setup like this in the app I am working on now. The trick is
to have one master admin controller with no action that the other admin
controllers inherit form
First generate your controller with
ruby script/generate controller admin/admin
You should now have an Admin::AdminController in
My Admin:AdminController looks like this:
class Admin::AdminController < ApplicationController
This way I am using a different layout and have a before filter that
takes care of the authorization (admin_required method is in
application.rb since it used in other places on the site).
Now create a child controller that you will actually use
ruby script/generate controller admin/foo
And change the first line from:
class Admin::FooController < ApplicationController
class Admin::FooController < Admin::AdminController
and do the same for all controllers in your admin directory. This keeps
your admin controllers clean and protected all from one spot.