Вопрос

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?

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top