Class: Kms::AssetsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Kms::AssetsController
- Defined in:
- app/controllers/kms/assets_controller.rb
Instance Method Summary collapse
- #ckeditor ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#ckeditor ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/kms/assets_controller.rb', line 19 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..first}'); </script>" end end |
#create ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/controllers/kms/assets_controller.rb', line 10 def create @asset = Asset.new(asset_params) if @asset.save render json: {success: true, files: [@asset]}.to_json else render text: '', status: :unprocessable_entity end end |
#destroy ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/kms/assets_controller.rb', line 46 def destroy @asset = Asset.find(params[:id]) @asset.destroy render json: @asset.to_json end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/kms/assets_controller.rb', line 6 def index render json: Asset.all.to_json(methods: [:filename, :url]) end |
#show ⇒ Object
39 40 41 42 43 44 |
# File 'app/controllers/kms/assets_controller.rb', line 39 def show @asset = Asset.find(params[:id]) attrs = {} attrs.merge!(methods: [:filename, :text]) if @asset.stylesheet_or_javascript? render json: @asset.to_json(attrs) end |
#update ⇒ Object
32 33 34 35 36 37 |
# File 'app/controllers/kms/assets_controller.rb', line 32 def update @asset = Asset.find(params[:id]) asset_params.merge!(text: params[:text], performing_plain_text: params[:performing_plain_text]) if params[:text] @asset.update_attributes(asset_params) render json: @asset.to_json end |