0

This is not working in my development environment.

I browsed around Google and SO for related posts, and tried everything mentioned here: Rails 4 image-path, image-url and asset-url no longer work in SCSS files

I've tried putting my image in the stylesheets directory, putting it in the images directrory, trying to access it with asset-url, image-url, url, from assets/images/my-image.jpg, images/my-image.jpg, my-image.jpg, assets/my-image.jpg, none of these work. I've checked development.rb in the config/environments and i'm not configured to serve_static_assets, although I'm precompiling some glyphcons in assets.rb and appending some text to that to precompile font files in application.rb, but I don't see how that would keep my images from being sent up by the server.

I checked that my stylesheets were getting sent by restyling some of my page, and they are getting served, so it is an issue of the images not being sent. I have been clearing the cache between test runs, as well, and have been receiving logs in the console that my desired image is searched for but then not found.

Any ideas as to what might be causing this? I'm running Rails 4.2.0 with ruby 2.1.5.

More Details: I discovered that this issue had something to do with the fact that my image contained the word 'bockground' in the image name. If somebody can answer the question of, "is it really the image name, as it seems, since changing the name of the image worked? Or is it deeper than that?" That would be great, but if not, Rails is huge, so could somebody give me a starting point in Rails for investigating the code to find out exactly what logic filters out images that either start with or contain the word 'background'?

I thought maybe Sprockets would be the place for this, but I'm not sure Sprockets actually sends the Assets, it just compiles them, and I'm not sure if it does anything with images or if it just handles compiling Sass and JavaScript and stuff... The Readme wasn't that specific about the role of Sprockets, if I was reading things correctly and fully.

Community
  • 1
  • 1
josiah
  • 1,314
  • 1
  • 13
  • 33
  • I just tried this out on a brand new project with the same effect - rails is not finding my image. – josiah Mar 01 '15 at 01:55
  • If I open up a Pry Rails Console session and cd into the app object and run the following code to take a look at what's available to sprockets, it returns my image's filepath. I don't know if that is helpful to anyone, but it's an indicator that my image might be getting lost along the way. `@app.assets.each_file { |f| puts f.to_s }` – josiah Mar 01 '15 at 04:34
  • I had a similar problem. Have you checked to see if the precompiled assets are in your public/assets directory? If they are, then try this: change your css to xxx.css.erb and for the url to the asset use: url(<%= asset_path "my-image.jpg" %>). The problem is that the file has the "digested" filename, not the original "my-image.jpg". The call to asset_path should fix that (at least, it did for me). – J Plato Mar 01 '15 at 05:14
  • @JPlato Thanks for the suggestion, but I tried it out with both the asset_path and image_path methods and neither one could find my image. I even added my image directly to the public/assets and public/assets/images directories with no success. I also tried adding and removing explicit commands to precompile files with image extensions and manually setting config.assets.paths. What's going on, why can't Rails, even on a fresh project, serve up my images? This is just frustrating. – josiah Mar 01 '15 at 20:21
  • Recent development, I tried a different JPG image and it works fine. There must be something about the image format of this particular JPG that Rails doesn't recognize? I would like to know why this is because I wish to use this image specifically. – josiah Mar 01 '15 at 20:29

2 Answers2

1

You didn't say, but I'm assuming that you've restarted your server - try stopping spring as well: spring stop

smathy
  • 26,283
  • 5
  • 48
  • 68
0

It turns out Rails was excluding any images called something similar to 'background.jpg', so renaming the image to something that doesn't include the word 'background' solved the problem.

josiah
  • 1,314
  • 1
  • 13
  • 33