I'm trying to put my app into production and image and css asset paths aren't working.
Here's what I'm currently doing:
- Image assets live in /app/assets/images/image.jpg
- Stylesheets live in /app/assets/stylesheets/style.css
- In my layout, I reference the css file like this:
<%= stylesheet_link_tag "styles", media: "all", "data-turbolinks-track" => true %>
- Before restarting unicorn, I run
RAILS_ENV=production bundle exec rake assets:precompile
and it succeeds and I see the fingerprinted files in thepublic/assets
directory.
When I browse to my site, I get a 404 not found error for mysite.com/stylesheets/styles.css
.
What am I doing wrong?
Update: In my layout, it looks like this:
<%= stylesheet_link_tag "bootstrap.min", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag "styles", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
The generate source is this:
<link data-turbolinks-track="true" href="/stylesheets/bootstrap.min.css" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/stylesheets/styles.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/application-0c647c942c6eff10ad92f1f2b0c64efe.js"></script>
Looks like Rails is not properly looking for the compiled css files. But it's very confusing why it's working correctly for javascripts (notice the /assets/****.js
path).
stylesheet_link_tag
. – kik<%= stylesheet_link_tag "style", media: "all", "data-turbolinks-track" => true %>
– emersonthispublic/assets
and 2. double check if there's not an other instruction somewhere trying to load that css file (presumably hard-coded) – kik.home {background: #FFF url(<%= image_path 'hippopotamus.jpg' %>) no-repeat; }
can actually be replaced in sprocket with.home {background: #FFF url(image-path('hippopotamus.jpg')) no-repeat; }
. Maybe you can try if this helps. – kik