Rails scaffold without the css file?

核能气质少年 提交于 2019-11-28 08:09:29

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

rails g scaffold MyModel --no-stylesheets

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!