sass-rails helpers "image-url", "asset-url" are not working in rails 3.2.1
Solution 1:
Despite what the documentation says, it seems the default options in rails 3.2.6 allow you to just make things work with even less path information in your CSS.
E.g. ../app/assets/images/rails.png
is references in your example.css.scss file with something like:
background: white url(rails.png) repeat-y;
You don't include the image-url
or asset-url
into your scss (as far as I know), just plain url(your_image.png)
. That bit of documentation appears to be just an explanation of what it is doing in the background.
Solution 2:
When I hit this problem, it was because I had not included the css file in the asset pipeline for pre-compilation. As a result, it would be generated at runtime. Because the sass-rails gem is commonly in the :assets group, the helpers are unavailable when generating css files at runtime.
Try adding the following line to your application.rb (or production.rb):
config.assets.precompile += %w( public/omg.css )
I found the fix on this post including a gotcha around naming the files when adding them to the precompiler.
Solution 3:
If you have updated your app to Rails 3.1 in the past, make sure you changed your application.rb file from
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
to
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
See this railscast on upgrading to Rails 3.1 and adding the asset pipeline.
Update: Rails 4 goes back to the old way of doing it. Thanks Aaron Gray!
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)