Class: PushType::AssetsController
- Inherits:
-
AdminController
- Object
- ActionController::Base
- AdminController
- PushType::AssetsController
- Defined in:
- app/controllers/push_type/assets_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #empty ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #restore ⇒ Object
- #trash ⇒ Object
- #update ⇒ Object
- #upload ⇒ Object
Methods inherited from AdminController
Instance Method Details
#create ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/controllers/push_type/assets_controller.rb', line 28 def create if @asset.save flash[:notice] = 'File successfully uploaded.' redirect_to push_type.assets_path else render 'new' end end |
#destroy ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/push_type/assets_controller.rb', line 63 def destroy if @asset.trashed? @asset.destroy flash[:notice] = 'Media permanently deleted.' redirect_to push_type.trash_assets_path else @asset.trash! flash[:notice] = 'Media trashed.' redirect_to push_type.assets_path end end |
#edit ⇒ Object
51 52 |
# File 'app/controllers/push_type/assets_controller.rb', line 51 def edit end |
#empty ⇒ Object
81 82 83 84 85 |
# File 'app/controllers/push_type/assets_controller.rb', line 81 def empty PushType::Asset.trashed.destroy_all flash[:notice] = 'Trash successfully emptied.' redirect_to push_type.assets_path end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/push_type/assets_controller.rb', line 9 def index respond_to do |format| format.html do @assets = PushType::Asset.not_trash.page(params[:page]).per(20) end format.json do @assets = PushType::Asset.not_trash.page(params[:page]).per(12) render json: { assets: view_context.assets_array(@assets).as_json, meta: { current_page: @assets.current_page, total_pages: @assets.total_pages } } end end end |
#new ⇒ Object
25 26 |
# File 'app/controllers/push_type/assets_controller.rb', line 25 def new end |
#restore ⇒ Object
75 76 77 78 79 |
# File 'app/controllers/push_type/assets_controller.rb', line 75 def restore @asset.restore! flash[:notice] = 'Media successfully restored.' redirect_to push_type.assets_path end |
#trash ⇒ Object
21 22 23 |
# File 'app/controllers/push_type/assets_controller.rb', line 21 def trash @assets = PushType::Asset.trashed.page(params[:page]).per(20) end |
#update ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/controllers/push_type/assets_controller.rb', line 54 def update if @asset.update_attributes asset_params flash[:notice] = 'Media successfully updated.' redirect_to push_type.assets_path else render 'edit' end end |
#upload ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/push_type/assets_controller.rb', line 37 def upload respond_to do |format| format.json do if @asset.save hash = params[:froala] ? { link: main_app.media_path(file_uid: @asset.file_uid) } : { asset: view_context.asset_hash(@asset).as_json } render json: hash, status: :created else hash = params[:froala] ? { error: @asset.errors..first } : { errors: @asset.errors.as_json } render json: hash, status: :unprocessable_entity end end end end |