0

I'm uploading Carrierwave images to the app/assets/images directory. To display them, I do this...

 <%= image_tag "/assets/#{File.basename(@user.image_url(:thumb).to_s)}" %>

The resulting HTML is <img src="/assets/thumb_1_1_leonel.jpg"> It works perfectly in development, NOT in production. The image is in fact, uploaded.

The permissions of the images uploaded are -rw-r--r--.

I already tried setting config.serve_static_assets to true (http://stackoverflow.com/questions/10612914/carrierwave-doesnt-render-path-exists-but-image-doesnt-show-up), then restarted Unicorn and ngnix, but I saw no change.

Why aren't they displayed?

leonel
  • 10,106
  • 21
  • 85
  • 129
  • are you storing them in different folders/filenames per environment? check your store_dir method in carrierwave – Kyle C Aug 14 '12 at 15:53
  • No, this is all I have in my store_dir method `Rails.root + "app/assets/images"` – leonel Aug 14 '12 at 16:23
  • I just gave 777 permissions to the jpgs that aren't being displayed, it didn't fix anything. – leonel Aug 14 '12 at 16:40
  • 1
    all you should need for carrierwave is <%= image_tag @user.image_url(:thumb).to_s %> , it stores the correct path in your database – Kyle C Aug 14 '12 at 17:03
  • If I do that, it displays the whole system path and I got no image showing in the page `` – leonel Aug 14 '12 at 17:07
  • You shouldn't be storing uploaded files in your assets folder in production, that is for static files. Change your store_dir to 'public/my/upload/directory' – Kyle C Aug 14 '12 at 17:13
  • The files are not supposed to be public. Where else can I upload them to? – leonel Aug 14 '12 at 17:20
  • 1
    If you dont want the images to be public then you will have to do some more work, check out this question http://stackoverflow.com/questions/8089933/showing-images-with-carrierwave-in-rails-3-1-in-a-private-store-folder – Kyle C Aug 14 '12 at 17:33
  • If we store it out side the application folder then what we have to do? – urjit on rails Sep 24 '13 at 15:51

1 Answers1

1

add this in production.rb

config.serve_static_assets = true
Chitresh goyal
  • 313
  • 1
  • 7
  • From the question: *"I already tried setting config.serve_static_assets to true "*. – Pang Feb 20 '16 at 04:52
  • config.serve_static_assets = true is deprecated, but thank you for the hint. I used config.serve_static_files = true to fix the problem. – guero64 Feb 01 '17 at 19:43