Rails scaffolds scss reset every time a scaffold is created

Every time I do rails generate scaffold Name , the app/assets/stylesheets/scaffolds.css.scss file is overwritten (well, I get an invitation to overwrite it). I don't want this, so of course I could just type n when I get a rewrite request, but I want to know how to properly handle scaffold styles.

I could just write css in the css file downloaded later to override the required css in the scaffolds.css.scss file. But not only this is ugly (due to unnecessary / unused css, each request is generated and loaded), but I donโ€™t know how not to change the foreground and background colors when hovering over links (from scaffolds.css.scss):

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

What is the correct way to remove something like above from scaffolds.css.scss ?

+4
source share
3 answers

Take a look at this fooobar.com/questions/234088 / ...

rails g scaffold MyModel --no-stylesheets

+6
source

Do you want to disable disabling the stylesheet permanently or, as a rule, forget --no-stylesheets switch (I DO!)

Disable the stylesheet in the generator!

configurations / application.rb

 config.generators do |g| g.stylesheets false end 
+13
source

Remember that you can always override these things in your own style sheets and include them later than the scaffold style sheets by changing the /stylesheets/application.css attributes

  *= require_self *= require scaffolds *= require YOUR_FILE 

(If you are not playing with application.css, by default, style sheets are included in alphabetical order, which may or may not be what you want.)

+1
source

Source: https://habr.com/ru/post/1438055/


All Articles