Search code examples
ruby-on-railsstylesheet

Rails stylesheet not loading


I am learning Rails and I encounter a prolem that i cannot find an answer for. I have 2 css files "print.css" and "screen.css" , both in "/public/stylesheets"

When I load them in "application.html.erb" in the layout and start the server, both files are missing from on the local website. This is the error:

GET http://localhost:3000/assets/print.css 404 (Not Found)

GET http://localhost:3000/assets/screen.css 404 (Not Found)

Here is the code from "application.html.erb":

<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <%= csrf_meta_tag %>
    <%= stylesheet_link_tag "screen", "print" %>

</head>
<body>
    <%= yield %>
</body>
</html>

Furthermore i have added this

config.assets.compile = true

to my "./config/environments/development.rb" and ran

bundle exec rake assets:precompile RAILS_ENV=development

to no avail.

Please advise!


Solution

  • Please read up on the asset pipeline. It is no longer common practice to put stylesheets (or javascript/images) in the public/ directory. Rather, they should be placed in app/assets/stylesheets/ where they can be precompiled and included with

    <%= stylesheet_include_tag 'application' %>