Class: Kms::AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kms/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_csrf_cookie_for_ng

Instance Method Details

#ckeditorObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/kms/assets_controller.rb', line 21

def ckeditor
  @asset = Asset.new(file: params[:upload])
  if @asset.save
    render text: %Q"<script type='text/javascript'>
        window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{@asset.file.url}');
      </script>"
  else
    render text: %Q"<script type='text/javascript'>
            window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, null, '#{@asset.errors.full_messages.first}');
          </script>"
  end
end

#createObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/kms/assets_controller.rb', line 11

def create
  @asset = Asset.new(asset_params)
  if @asset.save
    # special json for ng-flow
    render json: { success: true, files: [@asset] }.to_json
  else
    render json: { errors: @asset.errors.full_messages }.to_json, status: :unprocessable_entity
  end
end

#destroyObject



48
49
50
51
52
# File 'app/controllers/kms/assets_controller.rb', line 48

def destroy
  @asset = Asset.find(params[:id])
  @asset.destroy
  head :no_content
end

#indexObject



7
8
9
# File 'app/controllers/kms/assets_controller.rb', line 7

def index
  render json: Asset.all
end

#showObject



43
44
45
46
# File 'app/controllers/kms/assets_controller.rb', line 43

def show
  @asset = Asset.find(params[:id])
  render json: @asset
end

#updateObject



34
35
36
37
38
39
40
41
# File 'app/controllers/kms/assets_controller.rb', line 34

def update
  @asset = Asset.find(params[:id])
  if @asset.update(asset_params)
    render json: @asset
  else
    render json: { errors: @asset.errors.full_messages }.to_json, status: :unprocessable_entity
  end
end