Reputation: 10224
I have a js file that links to some images but I can't get it to work.
I have tried the js extension like this...
case 0: var padImg = 'hs.png'; break;
case 0: var padImg = '/assets/hs.png'; break;
I changed the file extension to js.erb and tried this...
case 0: var padImg = '<%= asset_path 'hs.png' %>'; break;
Then I moved the images to the js folder and it finally worked like this...
case 0: var padImg = 'hs.png'; break;
The weird thing is, it works in my development environment but it doesn't work on production. Why and how can I fix it?
Upvotes: 2
Views: 798
Reputation: 14943
This syntax is incorrect
case 0: var padImg = '<%= asset_path 'hs.png' %>'; break;
It should give a JavaScript error.
Try
case 0: var padImg = "<%= asset_path 'hs.png' %>"; break;
Normally for JavaScript/CoffeeScript and ERB you want to reference the image like
$('#logo').attr({
src: "<%= asset_path('logo.png') %>"
});
http://guides.rubyonrails.org/asset_pipeline.html
if that's not it, then what is the production server OS and web server using there if it's different from development?
Is it the only asset pipleine failing?
Edit
For Apache\JBoss to reference images in CSS I had to add the path\war name
so if my app root is localhost:3000/MyApp then to reference the image I had to do url(/MyApp/images/hs.png)
if you have js.erb you can do it like above and with css.erb you can do url(<%= asset_path 'hs.png' %>)
Upvotes: 2