2

I created a new fresh project in Rails 7, and whenever I use the generating script

rails generate scaffold or rails generate controller, all of the generated files are created except the css/scss.

Apparently, I'm not the only one with the issue

There's a claim on that link that in Rails 7, the CSS files are not generated by default.

Is there a way to force rails CLI to generate styles on the scaffold command?

And in anyway, why did they make that change in Rails 7, if the claim is true?

Here's the script I ran and the output in my given console:

rails g scaffold WhyNoCss dont_work:boolean
  invoke  active_record
  create    db/migrate/20220215221757_create_why_no_csses.rb
  create    app/models/why_no_css.rb
  invoke    test_unit
  create      test/models/why_no_css_test.rb
  create      test/fixtures/why_no_csses.yml
  invoke  resource_route
   route    resources :why_no_csses
  invoke  scaffold_controller
  create    app/controllers/why_no_csses_controller.rb
  invoke    erb
  create      app/views/why_no_csses
  create      app/views/why_no_csses/index.html.erb
  create      app/views/why_no_csses/edit.html.erb
  create      app/views/why_no_csses/show.html.erb
  create      app/views/why_no_csses/new.html.erb
  create      app/views/why_no_csses/_form.html.erb
  create      app/views/why_no_csses/_why_no_css.html.erb
  invoke    resource_route
  invoke    test_unit
  create      test/controllers/why_no_csses_controller_test.rb
  create      test/system/why_no_csses_test.rb
  invoke    helper
  create      app/helpers/why_no_csses_helper.rb
  invoke      test_unit
  invoke    jbuilder
  create      app/views/why_no_csses/index.json.jbuilder
  create      app/views/why_no_csses/show.json.jbuilder
  create      app/views/why_no_csses/_why_no_css.json.jbuilder
1
  • A half solution to this issue is directly generating the SCSS file by using the rails CLI command rails g scss:assets [scaffold NAME]. This would generate an empty style file in the app/assets/stylesheets directory. You'll still have to manually link the style to the views to. So ,again, why would I use this command when I can just create the stylesheet file in the code editor? Commented Feb 17, 2022 at 22:33

1 Answer 1

3

Is there a way to force rails CLI to generate styles?

While you can add --css sass (also: tailwind, postcss, bootstrap) to rails new commands, the ability to generate CSS files with a scaffold command was removed in v7.0.0.alpha1 (PR, commit).

And in anyway, why did they make that change in Rails 7, if the claim is true?

You can read the justification on the PR in addition to their blog post on Rails 7 that mentions CSS changes.

Sign up to request clarification or add additional context in comments.

7 Comments

Tried rails generate scaffold test title:string --css sass And it didn't generate any style file. I checked the command via rails generate scaffold --help, and again no css can be found in the output.
Looks like I was slightly off. This is available on rails new commands, not rails generate. An example can be found on this blog post.
Again, tried every option and it still won't generate style files when using scaffold command. The only thing it does is add famous CSS library, which is obvious from the assuming what the option does. I honestly don't understand their reason for not generating any JS & CSS files anymore. Every page needs it's own custom CSS and definitely needs some JS for making the page more responsive. Also, I read the blog post and not once did they mention the removal of generating CSS & JS files from rails generate scaffold command :/
To create new rails on a specific version, check this link I found just now: aloucaslabs.com/miniposts/…
About Rails 6.1.4.6, it actually did generate a StyleSheet file, but no JS file.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.