Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails scaffold without the css file?

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

like image 258
Brett Avatar asked May 11 '11 15:05

Brett


3 Answers

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

rails g scaffold MyModel --no-stylesheets
like image 189
Dylan Markow Avatar answered Nov 03 '22 12:11

Dylan Markow


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.

like image 36
ches Avatar answered Nov 03 '22 12:11

ches


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
like image 11
eikes Avatar answered Nov 03 '22 12:11

eikes