Sha256: c11f179438811f9baed0b50e64bf31582446facef0e17b8e5d806be844281aa3

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module Uploader
  module Asset
    # Save asset
    # Usage:
    #
    #   class Asset < ActiveRecord::Base
    #     include Uploader::Asset
    #
    #     def uploader_create(params, request = nil)
    #       self.user = request.env['warden'].user
    #       super
    #     end
    #   end
    #
    def uploader_create(params, request = nil)
      self.guid = params[:guid]
      self.assetable_type = params[:assetable_type]
      if self.class.respond_to?(:collection) && !params[:assetable_id].blank?
        if defined?( Moped::BSON )
          self.assetable_id = Moped::BSON::ObjectId.from_string(params[:assetable_id])
        else
          self.assetable_id = BSON::ObjectId.from_string(params[:assetable_id])
        end
      else
        self.assetable_id = params[:assetable_id]
      end

      save
    end

    # Destroy asset
    # Usage (cancan example):
    #
    #   class Asset < ActiveRecord::Base
    #     include Uploader::Asset
    #
    #     def uploader_destroy(params, request = nil)
    #       ability = Ability.new(request.env['warden'].user)
    #       if ability.can? :delete, self
    #         super
    #       else
    #         errors.add(:id, :access_denied)
    #       end
    #     end
    #   end
    #
    def uploader_destroy(params, request)
      destroy
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glebtv-rails-uploader-0.4.1 lib/uploader/asset.rb
glebtv-rails-uploader-0.4.0 lib/uploader/asset.rb