Paths to images in fixtures with Rails


#1

I am learning ember; using ember with a rails backend and the ember-rails gem.

I am using the FixtureAdapter. In my FIXTURES, I have a imageUrl attribute.

How should the imageUrl: "/path/to/images/image.png" be referenced if I place those images in the app/assets/images/ directory?

All help is appreciated.

Thanks DJ


#2

I figured this one out.

With the asset pipeline, one removes the /images/ directory.

Placing the image files in app/assets/image/ then, in FIXTURES , you reference imageUrl: ‘assets/image.png’


#3

It’s all well and good in development, but what about production, when your ‘assets/image.png’ gets transformed into something like ‘assets/image-lksadf8sdfkjsdf98sd7f9s8df.png’ how would you guess what is the correct path to the image through hard coding like this?


#4

I’ve not tried this in an Ember app but the Rails asset pipeline can run multiple pre-processors, so you could name your JS file store.js.erb, and then reference your image like so:

imageUrl: "<%= asset_path('image.png') %>"

See the ‘Coding Links to Assets’ and ‘Preprocessing’ sections of http://guides.rubyonrails.org/asset_pipeline.html for more info.