Reputation: 1753
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
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.
Upvotes: 1