Pregunta

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?

¿Fue útil?

Solución

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top