How do I use CSS with a ruby on rails application?

后端 未结 8 459
情书的邮戳
情书的邮戳 2020-12-01 04:00

How do I use CSS with RoR? When I link externally, I\'m never able to see the files. I cp\'d the .css file to every folder I could think of...views, controller, template, an

相关标签:
8条回答
  • 2020-12-01 04:53

    The original post might have been true back in 2009, but now it is actually incorrect now, and no linking is even required for the stylesheet as I see mentioned in some of the other responses. Rails will now do this for you by default.

    • Place any new sheet .css (or other) in app/assets/stylesheets
    • Test your server with rails-root/scripts/rails server and you'll see the link is added by rails itself.

    You can test this with a path in your browser like testserverpath:3000/assets/filename_to_test.css?body=1

    0 讨论(0)
  • 2020-12-01 04:55

    Use the rails style sheet tag to link your main.css like this

    <%= stylesheet_link_tag "main" %>
    

    Go to

    config/initializers/assets.rb
    

    Once inside the assets.rb add the following code snippet just below the Rails.application.config.assets.version = '1.0'

    Rails.application.config.assets.version = '1.0'
    Rails.application.config.assets.precompile += %w( main.css )
    

    Restart your server.

    0 讨论(0)
提交回复
热议问题