Skip to content

Instantly share code, notes, and snippets.

@mikepack
Forked from basgys/simple_paperclip.rb
Created July 26, 2013 19:36
Show Gist options
  • Save mikepack/6091652 to your computer and use it in GitHub Desktop.
Save mikepack/6091652 to your computer and use it in GitHub Desktop.
Convert to mixin
# == Paperclip without ActiveRecord
#
# Original: https://gist.github.com/basgys/5712426
require 'active_model/naming'
require 'active_model/callbacks'
require 'active_model/validations'
require 'paperclip'
require 'paperclip/glue'
module SimplePaperclip
def self.included(base)
base.extend ActiveModel::Naming
base.extend ActiveModel::Callbacks
base.send :include, ActiveModel::Validations
base.send :include, Paperclip::Glue
# Paperclip required callbacks
base.define_model_callbacks :save, only: [:after]
base.define_model_callbacks :destroy, only: [:before, :after]
end
# 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