Sha256: 0d11b3db78a4bffc334ddf631e4be4fe01dd1f327f6d0910d380e18744e5159c

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8
module Uploader
  class AttachmentsController < ActionController::Metal
    include AbstractController::Callbacks
  
    before_filter :find_klass
    
    def create
      @asset = @klass.new(params[:asset])
      @asset.uploader_create(params, request)
      render_resourse(@asset, 201)
    end
    
    def destroy
      @asset = @klass.find(params[:id])
      @asset.uploader_destroy(params, request)
      render_resourse(@asset, 200)
    end
    
    protected
    
      def find_klass
        @klass = params[:klass].blank? ? nil : params[:klass].safe_constantize
        raise ActionController::RoutingError.new("Class not found #{params[:klass]}") if @klass.nil?
      end
      
      def render_resourse(record, status = 200)
        if record.errors.empty?
          render_json([record].to_json(:root => false), status)
        else
          render_json([record.errors].to_json, 422)
        end
      end
      
      def render_json(body, status = 200)
        self.status = status
        self.content_type = "application/json"
        self.response_body = body
      end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rails-uploader-0.0.8 app/controllers/uploader/attachments_controller.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.7/app/controllers/uploader/attachments_controller.rb
rails-uploader-0.0.7 app/controllers/uploader/attachments_controller.rb
rails-uploader-0.0.6 app/controllers/uploader/attachments_controller.rb
rails-uploader-0.0.5 app/controllers/uploader/attachments_controller.rb
rails-uploader-0.0.4 app/controllers/uploader/attachments_controller.rb