3

In my Rails 3.2 app's application.rb I have the following lines to disable scaffold generators I don't want:

module MyApp
  class Application < Rails::Application

    # rest of the config...

    config.generators do |g|
      g.helper false
      g.stylesheets false
      g.javascripts false
    end
  end
end

The app is using the Draper gem and if I run rails generate then decorator is listed as one of the available generators. I assumed that adding g.decorator false to the above list would prevent rails generate scaffold SomeModel from generating the decorator files but they're still created. Can anyone tell me what I'm missing please?

Simon
  • 1,716
  • 1
  • 21
  • 37
  • 1
    Is this really an issue for you? I haven't used scaffolding since I first started learning Rails. If you're disabling so much of the scaffolding functionality, why not just use the controller generator? http://stackoverflow.com/questions/6735468/why-do-ror-professionals-not-use-scaffolding – deefour Feb 25 '13 at 16:37
  • 1
    I'm building a large app with a lot of models which already has all of it's HTML mocked up so I've customised the view generators (and added i18n support). It's worth it for the time that typing `rails g scaffold Thing title body:text option:boolean amount:integer other_thing:references` saves me :) – Simon Feb 25 '13 at 17:09

1 Answers1

4

Draper is configured to have decorators built by default for every controller. You can change the default configuration with one additional line in your application.rb file...

module MyApp
  class Application < Rails::Application

    # rest of the config...

    config.generators do |g|
      g.helper false
      g.stylesheets false
      g.javascripts false
      g.decorator   false
    end
  end
end

Here's the interesting bit from Draper...

https://github.com/drapergem/draper/blob/master/lib/generators/controller_override.rb

Called from the Railtie...

https://github.com/drapergem/draper/blob/master/lib/draper/railtie.rb

Note that you can still generate decorators explicitly...

$ rails generate decorator foo
Darren
  • 599
  • 5
  • 9