avian
avian

Reputation: 1753

How to stop CarrierWave from returning full avatar photo object when querying user record?

I have a User model with an avatar field that uses CarrierWave to manage the file. When I query the User table (e.g. User.where(...)) and send it down the pipeline via JSON, the avatar field becomes something that looks like this:

[{"avatar"=>{"url"=>"https://xyz.s3.amazonaws.com/uploads/user/avatar/avatar.jpg", :thumb=>{"url"=>"https://xyz.amazonaws.com/uploads/user/avatar/thumb_avatar.jpg"}, :full=>{"url"=>"https://xyz.amazonaws.com/uploads/user/avatar/full_avatar.jpg"}}}]

But when I look int the database, all I see is avatar.jpg in the avatar field. It seems that CarrierWave is appending all this extra info.

How can I just get the avatar.jpg that is in the db and not all this other stuff? My "hack" way was to do this User.where(...).select("avatar as avatar_file") but I'd prefer to find a cleaner solution.

Thanks! Aaron

Upvotes: 0

Views: 85

Answers (1)

Yann VERY
Yann VERY

Reputation: 1819

I think you can retrieve avatar filename with the avatar_identifier method ( that is accessible for each instance of user ) and include it in you json.

source: https://github.com/carrierwaveuploader/carrierwave/blob/88352b4de06d68c4994e7ad22b50a6863380931f/lib/carrierwave/mount.rb

Upvotes: 1

Related Questions