Are we supposed to use something else aside from image-url
and others in Rails 4? They return different values that don't seem to make sense. If I have logo.png
in /app/assets/images/logo.png
and I do the following, this is what I get:
image-url("logo.png") -> url("/images/logo.png") #obviously doesn't work image-path("logo.png") -> "/images/logo.png" asset-url("logo.png") -> url("/logo.png")
Of course none of these work because they need at least /assets
in front.
UPDATE: Actually, I just noticed, how do I access images in Rails 4? I have an image at /app/assets/images/logo.png
. But if I go to any of the following URLs, I still don't see my image:
http://localhost:3000/assets/logo.png http://localhost:3000/assets/images/logo.png http://localhost:3000/logo.png http://localhost:3000/images/logo.png
UPDATE 2: The only way I can bring up my logo.png
is by moving it into the /app/assets/stylesheets
directory and then pulling up:
http://localhost:3000/assets/logo.png
I just had this issue myself. 3 points that will hopefully help:
app/assets/images
directory, then you should be able to call the image directly with no prefix in the path. ie. image_url('logo.png')
background-image:
property, then your line of code should be background-image: image-url('logo.png')
. This works for both less and sass stylesheets. If you are using it inline in the view, then you will need to use the built in image_tag
helper in rails to output your image. Once again, no prefixing <%= image_tag 'logo.png' %>
rake assets:precompile
to generate your assets, or rake assets:precompile RAILS_ENV=production
for production, otherwise, your production environment will not have the fingerprinted assets when loading the page.Also for those commands in point 3 you will need to prefix them with bundle exec
if you are running bundler.
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