I have a Rails app with the following in /app/assets/stylesheets/styles.css.erb
:
...
#nestedbg {
background-position: left top;
background-image: url(<%= asset_path 'siteheader2.png' %>);
background-repeat: repeat-x;
background-attachment: fixed;
}
...
When I run rake assets:precompile
and then run rails s -e production
, everything works as expected. However, when I remove the precompiled assets and run rails s
in development, the CSS file comes up as shown above instead of being properly substituted.
I tried putting config.assets.compile = true
in /config/environments/development.rb
and that did not help.
Any ideas? Thanks.
I honestly cannot say why this is not interpreted correctly in your case, but I have a much better workaround to offer: skip erb interpreting altogether.
You can do this like so:
/* styles.css.scss */
background-image:url(image_path("siteheader2.png"));
If you did not have a chance to I would also suggest to have a look at SASS: it is integrated in the Rails asset pipeline and lets you do cool things like variable declarations, nesting, mixins, ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With