views:

377

answers:

2

Hy,

I'm wondering what's the best way to create an Admin (backend) section in a Grails app ?

I want to create an Admin folder in the Controllers folder of Grail to put all my admin controllers. But Then will I have to create manually the URL mapping for each Admin controllers ?

I have already generate all my frontend gsp with the gerenate-all command which takes a domain class but know how can I generate my CRUD for my admin section (with the same domain class). Am I screwed ?

Thanks a lot for your tips!

+1  A: 

You could create your admin controllers like any other controller and use a filter to make sure only logged in users with admin privilages can access them.

Jared
Ok thanks it's working well if I create manually a second controller, but how do I generate 2 controllers from 1 domain class ? (something like /CommentController and /admin/CommentController from my Comment.groovy class ?)
Wickramben
+2  A: 

My preference for this is to have a separate application for admin. Stick all of your domain classes in a plugin and install that plugin into both the admin application and the consumer appilcation.

That way, you can tweak the controllers to your hearts content and not worry about end users hitting them. Shared services can also be in the domain plugin.

There's a special file that you can put in your grails-app/conf called BuildConfig.groovy where you can specify "local" plugins like the domain plugin that are automatically brought into the classpath without having to package/install the plugin. Makes it super easy.

Ted Naleid
Thanks a lot! I like the way you split the Admin and the Front. About the "BuildConfig.groovy" file, do I have to add the "grails.project.plugins.dir" property to bring the plugin domain classes to my Grails app classpath ?
Wickramben
Nope, just let it know where the plugin is on your local disk. Here are the contents of my grails-app/conf/BuildConfig.groovy file in an application that I have my "domain" plugin installed into: grails.plugin.location.domain = "../domain"It automatically adds all of the necessary stuff to my classpath from that domain plugin when running/packaging/warring the app.(weird formatting on comments hopefully that makes sense)
Ted Naleid
Oh ok I get it! Thanks so much for your help!
Wickramben