Skip to content

Instantly share code, notes, and snippets.

@suhovius
Forked from basgys/simple_paperclip.rb
Created February 12, 2014 14:38
Show Gist options
  • Save suhovius/8956669 to your computer and use it in GitHub Desktop.
Save suhovius/8956669 to your computer and use it in GitHub Desktop.
# == Paperclip without ActiveRecord
#
# Simple and lightweight object that can use Paperclip
#
#
# Customized part can be extracted in another class which
# would inherit from SimplePaperclip.
#
# class MyClass < SimplePaperclip
# attr_accessor :image_file_name # :<atached_file_name>_file_name
# has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }
#  end
#
# author : Bastien Gysler <[email protected]>
class SimplePaperclip
extend ActiveModel::Naming
extend ActiveModel::Callbacks
include ActiveModel::Validations
include Paperclip::Glue
# Paperclip required callbacks
define_model_callbacks :save, only: [:after]
define_model_callbacks :destroy, only: [:before, :after]
# Paperclip attached file example
# -- Customize here --
attr_accessor :image_file_name # :<atached_file_name>_file_name
has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }
# -- /Customize here --
# ActiveModel requirements
def to_model
self
end
def valid?() true end
def new_record?() true end
def destroyed?() true end
def errors
obj = Object.new
def obj.[](key) [] end
def obj.full_messages() [] end
obj
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment