Class: RedactorRails::DocumentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controller/redactor_rails/documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controller/redactor_rails/documents_controller.rb', line 10

def create
  @document = RedactorRails.document_model.new

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

  if @document.save
    render json: { filelink: @document.url, filename: @document.filename }
  else
    render json: { error: @document.errors }
  end
end

#indexObject


4
5
6
7
8
# File 'app/controller/redactor_rails/documents_controller.rb', line 4

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