Chris Yeung
Chris Yeung

Reputation: 2723

How to access cloudinary attributes in rails?

Given the following output from f.object.filename.inspect from a form. And I am using carrierwave.

$> <CarPhotoUploader:0x007f83efa788f0 
    @model=#<CarPhoto id: 19, filename: "image/upload/v1433056939/eio6d7b0dtfdjptmxud4.png", car_id: 19, document: nil, created_at: "2015-05-31 07:22:04", updated_at: "2015-05-31 07:26:45">, 
    @mounted_as=:filename, 
    @transformation={}, 
    @file=#<Cloudinary::CarrierWave::CloudinaryFile:0x007f83efa786e8 
        @uploader=#<CarPhotoUploader:0x007f83efa788f0 ...>, 
    @identifier="image/upload/v1433056939/eio6d7b0dtfdjptmxud4.png", 
    @resource_type="image", 
    @storage_type="upload", 
    @version="1433056939", 
    @filename="eio6d7b0dtfdjptmxud4.png", 
    @public_id="eio6d7b0dtfdjptmxud4", 
    @format="png">, 
    @stored_public_id="eio6d7b0dtfdjptmxud4", 
    @public_id="eio6d7b0dtfdjptmxud4", 
    @stored_version="1433056939", 
    @original_filename="eio6d7b0dtfdjptmxud4.png">

I need to access the @public_id but I can't get anything out but nil when I do

f.object.filename.public_id.

What should I do?

Upvotes: 0

Views: 240

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118261

f.object.filename.public_id gives nil.

Because that's how they have implemented. Look at there source code.

What you want is my_public_id.

So working code is : f.object.filename.my_public_id.

Upvotes: 2

Related Questions