William Pramana William Pramana - 11 months ago 86
JSON Question

Rails json output carrierwave thumbnail version

I need to render out a json output from a controller and I'd like to include the thumbnail version of my images in the json.

If I render json using only

it outputs the full image url, if I use
then it will lists all the available images (including thumbnail).

How do I render out in json just the thumbnail version of the image?



You should use something like this.

class ArtworkSerializer < ActiveModel::Serializer
    attributes :id, :name, :image_url

    def image_url

Then in your JSON response, you will have an attribute :image_url.

Note: You should have a version defined :thumbnail in your carrierwave uploader.