Jared
Jared

Reputation: 39877

Stopping Grails from generating certain methods in a controller?

In Spring Roo if I don't want a specific method to automatically be generated I can remove an annotation. Is there a way to do this in Grails? For example I would like the list and create methods of a controller to automatically be updated with any changes in the domain model when I do a generate-all, but would like to use custom code for the show method that does not get changed unless I manually edit it.

Upvotes: 2

Views: 132

Answers (2)

Burt Beckwith
Burt Beckwith

Reputation: 75671

Run 'grails install-templates' and it will copy the template scripts that are used to generate the controller, GSPs, etc. Edit those to have the methods that you want.

This isn't as flexible as Roo in that it's global and not available per-instance but if you want the same structure for all controllers then it'll work for you.

Upvotes: 1

Dónal
Dónal

Reputation: 187499

If you provide an action in a dynamic scaffolding controller then Grails won't create that action at runtime (but it will create all the others). So if you don't want the show action to be updated do this

class SomeDomainObjectController {
  def scaffold = SomeDomainObject

  def show = {
    // Your logic for this action goes here
  }
}

Upvotes: 2

Related Questions