6

Each time I do a rails generate scaffold Name, the app/assets/stylesheets/scaffolds.css.scss file is overwritten (well I get prompted to overwrite it). I don't want this, so of course I could just type n when prompted to overwrite, but I want to know the proper way to handle styling of scaffolds.

I could just write the css in a css file loaded later to override the necessary css in the scaffolds.css.scss file. But not only is that ugly (have unnecessary/unused css being generated and loaded every request), but I don't know how to not change the foreground and background colors upon hovering over links (from scaffolds.css.scss):

a {
  &:hover {
    color: #fff;
    background-color: #000;
  }
}

What's the proper way to remove something like the above from scaffolds.css.scss?

at.
  • 50,922
  • 104
  • 292
  • 461

3 Answers3

18

Want to disable disable stylesheet forever, or usually forgot --no-stylesheets switch(I DO!)

Disable stylesheet in your generator!!

config/application.rb

config.generators do |g|
 g.stylesheets false
end
Naveed
  • 11,057
  • 2
  • 44
  • 63
8

Look at this StackOverflow answer

rails g scaffold MyModel --no-stylesheets

Community
  • 1
  • 1
claptimes
  • 1,615
  • 15
  • 20
  • So to change stylesheets for scaffolds, we are supposed to modify scaffolds.css.scss and then just not generate the stylesheets for scaffolds? – at. Oct 05 '12 at 18:34
  • I think it's a bit of a discussion, but scaffolding is considered great for rapid prototyping. Once you're set with the models or have a good start, you can modify the code or start from scratch if you know what you want. More discussion [here](http://programmers.stackexchange.com/questions/75011/do-experienced-ruby-on-rails-developers-use-scaffolding) – claptimes Oct 05 '12 at 18:55
  • 1
    My question was about the proper way to modify stylesheets for scaffolds (which seem to get included in all webpages in Rails by default too), not when and whether scaffolding is useful. – at. Oct 05 '12 at 19:16
1

Remember that you can always redefine these things in your own stylesheets, and include them later than the scaffolding stylesheets by modifying assets/stylesheets/application.css

 *= require_self
 *= require scaffolds
 *= require YOUR_FILE

(If you don't fiddle with application.css, by default the stylesheets get included in alphabetical order, which may or may not be what you want.)

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83