Sha256: 405fa7a6ddef08c05ef850946ab4245a2c3126c3345530e503df0efa908d754e

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

class RedactorRails::DocumentsController < ApplicationController
  before_filter :redactor_authenticate_user!

  def index
    @documents = RedactorRails.document_model.where(
        RedactorRails.document_model.new.respond_to?(RedactorRails.devise_user) ? { RedactorRails.devise_user_key => redactor_current_user.id } : { })
    render :json => @documents.to_json
  end

  def create
    @document = RedactorRails.document_model.new

    file = params[:file]
    @document.data = RedactorRails::Http.normalize_param(file, request)
    if @document.respond_to?(RedactorRails.devise_user)
      @document.send("#{RedactorRails.devise_user}=", redactor_current_user)
      @document.assetable = redactor_current_user
    end

    if @document.save
      render :text => { :filelink => @document.url, :filename => @document.filename }.to_json
    else
      render :nothing => true
    end
  end

  private

  def redactor_authenticate_user!
    if RedactorRails.document_model.new.respond_to?(RedactorRails.devise_user)
      super
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redactor-rails-0.4.3 app/controller/redactor_rails/documents_controller.rb
redactor-rails-0.4.2 app/controller/redactor_rails/documents_controller.rb
redactor-rails-0.4.1 app/controller/redactor_rails/documents_controller.rb
redactor-rails-0.3.7 app/controller/redactor_rails/documents_controller.rb
redactor-rails-0.3.6 app/controller/redactor_rails/documents_controller.rb