0

This is the CSS in my page.css.scss

#test {
  background-image: image-url("bigstock.jpg")
}

This is my routes.rb

Rails.application.routes.draw do
  get ':controller(/:action(/:id))'
  root 'page#index'

When I visit localhost:3000 I see the texts but no image. When I try to navigate to the address in the CSS, http://localhost:3000/assets/bigstock.jpg, I get the error message:

No route matches [GET] "/assets/bigstock-blured-lighhts-from-peak-Victo-63827467.jpg"

I am new to rails and have tried many different methods here like using asset-url, background, image_path but nothing works.

I couldn't do try setting config.serve_static_assets = true though as it throws some errors.

Since this is a fresh install, it shouldn't be too difficult to do something so simple? I guess I might be heading in the wrong direction.

Update: I have just tried config.serve_static_assets = true. Didn't help. Added it in the wrong place intially.

Community
  • 1
  • 1
resting
  • 16,287
  • 16
  • 59
  • 90
  • What were the errors with `serve_static_assets` turned on? – Austin Mullins Jul 18 '14 at 05:06
  • `undefined local variable or method 'config' for main:Object` when I start the server. Read that its for older version of Rails, but I'm not sure. – resting Jul 18 '14 at 05:10
  • 1
    The error message is saying that the file name is `bigstock-blured-lighhts-from-peak-Victo-63827467.jpg`.Is your file is `bigstock.jpg` or `bigstock-blured-lighhts-from-peak-Victo-63827467.jpg`? – Pavan Jul 18 '14 at 05:34
  • Hm..interesting I wanted to try renaming the filename to `bigstock` but probably changed a wrong location. I just tried renaming the file in `/asset/images/` and it worked. So long filenames is the problem? – resting Jul 18 '14 at 05:43
  • What is the original name of your file before you renamed? – Pavan Jul 18 '14 at 05:51
  • from `bigstock-blured-lighhts-from-peak-Victo-63827467.jpg` to `bigstock.jpg`. shall try adding some hypens later and see if it breaks. – resting Jul 18 '14 at 17:18

1 Answers1

0

The filename was the problem here. Removing the last hypen and numbers worked. I also realized that the image doesn't load if the filename ends with hypen, followed by a string of numbers with length greater than 6.

resting
  • 16,287
  • 16
  • 59
  • 90