Wednesday, May 16, 2012

Multiple Carrierwave mount_uploader on a single model

I have a model called Recipe which has 2 images that use carrierwave, so in this model i have this to setup carrierwave



mount_uploader :author_photo, AuthorUploader
mount_uploader :photo, PhotoUploader


I have also added multiple version to my images such as thumb, small, medium, large



The problem is. say i have 2 images



Chocolate_Cake.jpg as the photo
My_Photo.jpg as author_photo


When i go into console and load up my recipe and to recipe.to_json, I get both my images back from carrierwave but they are both showing the photo for the recipe, not the author photo.



     "recipe": [
{
"author_photo": {
"url": "/uploads/recipe/photo/8/Chocolate_Cake.jpg",
"thumb": {
"url": "/uploads/recipe/photo/8/thumb_Chocolate_Cake.jpg"
},
"small": {
"url": "/uploads/recipe/photo/8/small_Chocolate_Cake.jpg"
},
"medium": {
"url": "/uploads/recipe/photo/8/medium_Chocolate_Cake.jpg"
},
"large": {
"url": "/uploads/recipe/photo/8/large_Chocolate_Cake.jpg"
}
},
"id": 8,
"photo": {
"url": "/uploads/recipe/photo/8/Chocolate_Cake.jpg",
"thumb": {
"url": "/uploads/recipe/photo/8/thumb_Chocolate_Cake.jpg"
},
"small": {
"url": "/uploads/recipe/photo/8/small_Chocolate_Cake.jpg"
},
"medium": {
"url": "/uploads/recipe/photo/8/medium_Chocolate_Cake.jpg"
},
"large": {
"url": "/uploads/recipe/photo/8/large_Chocolate_Cake.jpg"
}
},


So for some reason my json response isnt showing my uploaders properly.



If i was to type this in console,



 recipe.photo
recipe.author_photo


They come up with different image urls





1 comment: