0

How to change user avatar to a picture that is in app/assets/images with carrierwave?

I have avatar_uploader.rb.

In my application there are several avatars to choose from, when I click on one of them, I send ajax request to controller with name of the picture.

What method do I need to use in controller to change user avatar to this picture?

I know the user.remote_avatar_url method for changing avatar using url of picture.

But I need a picture from assets/images/

RomanOks
  • 692
  • 3
  • 13

1 Answers1

0

Did you try this solution from official docs?

restaurant = Restaurant.create!(name: "McDonald's")
restaurant.logo = Pathname.new(Rails.root.join("db/images/mcdonalds_logo.png")).open
restaurant.save!

There is also similar question asked here: https://stackoverflow.com/a/16137722/4414956

nuaky
  • 2,036
  • 1
  • 14
  • 20
  • Yes, I tried. But it seemed to me that this method greatly affects performance on production server. Let me know if this method does not affect performance. Thanks. – RomanOks Oct 10 '19 at 13:03