0

How can I print out an image tag to a Rails asset in javascript?

If I have an image at /assets/images/my_image.png, the following will show an image in development, but not in a production.

$('.myImage').html('<img src="/assets/images/my_image.png">');

4
  • "/assets/my_image.png" doesn't work? Commented Nov 16, 2014 at 7:47
  • Nah - you can see the image asset missing here - dailydebate.co. If you click "agree" or "disagree" you should see the missing image icon. Commented Nov 16, 2014 at 7:50
  • other images in the app are working fine? whatis the value of config.serve_static_assets in prod.rb Commented Nov 16, 2014 at 7:52
  • config.serve_static_assets = false... so that sounds like a good thing to change. Does that hurt something else? guides.rubyonrails.org/configuring.html Commented Nov 16, 2014 at 7:53

1 Answer 1

1

For heroku

  config.serve_static_assets = true

also use

gem 'rails_12factor', group: :production

heroku docs has good explanation you need to check out once.

Sign up to request clarification or add additional context in comments.

3 Comments

Hmm, this still doesn't seem to solve it. I'll move it into /public for now
config.assets.compile = true is set? which version of rails?
I see the image in your app now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.