Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

How to check image version exists od not in carrierwave rails

Some pictures have mobile version or some have not. I want to check either mobile version existing or not

I used

image.mobile.file.exists?

But it also giving error

NoMethodError: undefined method `mobile' for

How can I check that?

Upvotes: 0

Views: 251

Answers (1)

Mark
Mark

Reputation: 6445

You don't have an image version called 'mobile' defined in your uploader.

If you've called your uploader ImageUploader, then open up app/uploaders/image_uploader.rb

Add the following version to the file:

  version :mobile do
    process resize_to_fill: [620, 270]
  end

Swap out the x and y sizes for whatever you need. After this all new images will have the 'mobile' attribute available. If you want it to apply to all old images, then you will need to save them and the new version will be available.

Upvotes: 1

Related Questions