Class: Redactor2Rails::FilesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controller/redactor2_rails/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controller/redactor2_rails/files_controller.rb', line 4

def create
  @file = Redactor2Rails.file_model.new

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

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