26

Is there a way to generate a scaffold in rails 3.0 so that scaffold.css does NOT get created? Something at the command line I can enter to skip that step?

Thanks

Dylan Markow
  • 117,383
  • 23
  • 273
  • 197
Brett
  • 2,675
  • 4
  • 25
  • 32

3 Answers3

69

There is a --no-stylesheets flag you can use:

rails g scaffold MyModel --no-stylesheets
Dylan Markow
  • 117,383
  • 23
  • 273
  • 197
  • 3
    NOTE: this will also disabling resource specific stylesheets, i.e. `app/assets/stylesheets/my_model.css.scss` won't be created – wik Oct 15 '12 at 17:48
  • 3
    Utilizing `--no-stylesheets` is a good idea if your app uses Twitter Bootstrap, because the `scaffold.css` file that Rails generates overrides quite a few of Bootstrap's styles. – XåpplI'-I0llwlg'I - Jun 15 '13 at 13:31
46

You can also disable it by default -- in config/application.rb:

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

Rails itself only uses it for scaffold.css AFAIK, but unfortunately the same hook could be used by other generators, so you might need to remember to pass --stylesheets for a third-party gem that generates assets, for instance. It'd be really nice if Rails had an explicit option for scaffold.css :-/

You can find other generator options in the Rails Guides, by the way. Helpers are nice to turn off by default and generate them when you actually want them.

ches
  • 5,417
  • 1
  • 32
  • 29
  • rails has an option to specifically disable the scaffold.css: ```g.scaffold_stylesheet false``` – eikes Dec 16 '16 at 11:18
  • Thanks @eikes, fairly certain that setting didn't exist in Rails 3 days but if the question/tags are updated for current versions I'll happily give your answer my vote. – ches Dec 16 '16 at 11:22
11

Since Rails 5.0, there is a configuration in config/application.rb which specifically disables generating the app/assets/stylesheets/scaffolds.css, but still generates the stylesheets for your new resource:

config.generators do |g|
  g.scaffold_stylesheet false
end

You can also pass it in as the --no-scaffold-stylesheet command line option:

rails generate scaffold post title body:text --no-scaffold-stylesheet
eikes
  • 4,012
  • 2
  • 25
  • 26