CarrierWave file exists?

If you ever wondered how to check for file if exist while you were using carrierwave gem with storage on amazon S3 here is how.

Assuming you have User class:

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

and uploader class
class AvatarUploader < CarrierWave::Uploader::Base
  storage :fog
end

then only thing that you have to do is this

user = User.first
user.avatar.file.exists?

thats it. I kind of assumed that it should be simple avatar.exist? but you have to get fog instance of file to be able to access exists? method.

Ckeditor with Amazon S3 and paperclip.

I was working on project recently, where I had to use CKeditor with paperclip and amazon s3 as the storage. This all is running on Heroku. The solution is really easy. You have the paperclip in you model

has_attached_file :avatar,
 :styles => { :big => "180x180#", :medium => "140x140#" },
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"
And you have something like this in the picture.rb and attachment_file.rb (app/model/ckeditor/)
has_attached_file :data,
     :url => "/ckeditor_assets/attachments/:id/:filename",
     :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename"

So solution is obvious now:

has_attached_file :data, :styles => { :big => "180x180#", :medium => "140x140#"},
 :storage => :s3,
 :s3_credentials => "#{Rails.root}/config/s3.yml",
 :path => ":attachment/:id/:style.:extension",
 :url => ":s3_domain_url"

That’s it.