Topic: Haw to create multu sections admin zone ?

pealse show me  the best way for admin zone in rails.
I need
1) protected scaffold mvc for data admining
2) public controller for showing this in to all user

path of privat zone : site_name/admin/skills
public zone:  site_name/skills

Please advise
Thanks
Dmitry

Re: Haw to create multu sections admin zone ?

Can anybody help me ?

Re: Haw to create multu sections admin zone ?

You need an admin namespace and two master controllers. The reason for the two controllers will become clear.

Normally in a standard rails apps all controllers descend directly from the application controller.
You would normally have one layout and for all the controllers that determines what views get rendered via menu links and this is where you lay out your website.
What you want is two of these instead of one.

The best way to achieve this is to have a public controller and an admin controller and have all other controllers descending from either of these instead of the application controller. Pick the name of the public controller carefully as this will determine the urls for the public side of your application, but there are ways to set your routes so it's not too important, just make sure it's something you are comfortable with.

The admin controller needs an authorization before filter to make sure that ALL actions in the controllers descending from the admin controller are secure and can't do anything without a valid user being logged in.

But if you just set up an admin controller with an authorization method it's very easy to let a controller slip through the net by forgetting to change the association and this is where having two controllers come in

If you set a before filter to call an authorize method in the application controller but DO NOT define that method in the application controller, any controllers that you forget to change the descendant class on will immediately throw an error.
All you need to do is define an empty authorize method in the public controller and a full authorization method in the admin controller.

Now you can have one layout for the public controller and a different layout for the admin controller allowing you to style the public side and the admin side totally differently from each other with totally different menus, headers, footers, side bars etc.

Kinda like having two apps in one but sharing the business logic. Pretty neat me thinks smile

When your head is hurting from trying to solve a problem, stop standing on it.
Then when you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Haw to create multu sections admin zone ?

Thanks for this James. I have have been having the same bit of trouble for a while. This solves the problem with access control. There are a few application design questions that I have as a result of this solution though:

  • is it still possible to use REST style forms using this solution?

  • do you actually throw all controllers/views into their respective sub-directories (e.g. admin/ and pub/) or keep it in the base app/controller directory?

Re: Haw to create multu sections admin zone ?

The quick answer is yes and controllers go in the respective namespace. You still scaffold everything but then you do a little re-factoring to enable things to run exactly as you would expect.
I stumbled on this when I was first sussing this out last year and I still use it to great effect and shows you exactly what you need to do.
http://icebergist.com/posts/restful-adm … ent-page-1
Hope that helps

When your head is hurting from trying to solve a problem, stop standing on it.
Then when you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)