Class: AssetManager::AssetsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AssetManager::AssetsController
- Defined in:
- app/controllers/asset_manager/assets_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #quick_upload ⇒ Object
- #select ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 29 def create @asset = Asset.new(params[:asset]) if @asset.save redirect_to edit_asset_url(@asset), flash: { success: t('asset_manager.assets.controller.asset_successfully_create') } else @asset = build_translations(@asset) @asset = build_asset_instances(@asset) render action: 'new' end end |
#destroy ⇒ Object
51 52 53 54 55 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 51 def destroy @asset = Asset.find(params[:id]) @asset.destroy redirect_to assets_url end |
#edit ⇒ Object
23 24 25 26 27 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 23 def edit @asset = Asset.find(params[:id]) @asset = build_translations(@asset) @asset = build_asset_instances(@asset) end |
#index ⇒ Object
7 8 9 10 11 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 7 def index @search = AssetManager::Asset.(params[:search]) @assets = @search.relation.send(Kaminari.config.page_method_name, params[Kaminari.config.param_name]).per(50).order('id DESC') @total_records = @search.relation.count end |
#new ⇒ Object
17 18 19 20 21 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 17 def new @asset = Asset.new(public: @public) @asset = build_translations(@asset) @asset = build_asset_instances(@asset) end |
#preview ⇒ Object
57 58 59 60 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 57 def preview @assets = Asset.find_ordered(params[:ids]) render partial: '/admin/asset_manager/assets/assets', locals: { collection: @assets } end |
#quick_upload ⇒ Object
97 98 99 100 101 102 103 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 97 def quick_upload if params[:asset][:translations_attributes]['0'][:title].blank? tilte_by_filename = File.basename(params[:asset]["asset_#{params[:asset][:public] == 'true' ? 'public' : 'private'}_instances_attributes".to_sym]['0'][:file].original_filename, '.*').titleize params[:asset][:translations_attributes]['0'][:title] = tilte_by_filename end @asset = Asset.create(params[:asset]) end |
#select ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 62 def select @owner = params[:owner] @id = params[:id] @field = params[:field] @save = params[:save] @locale = params[:locale] @field_name = params[:field_name] owner_class = @owner.constantize fail ActiveRecord::RecordNotFound.new('Invalid Field') unless owner_class.am_has_field?(@field) @multiple = owner_class.am_multiple_field?(@field.to_sym) @max = owner_class.am_field_option(@field, :max) @type = owner_class.am_field_option(@field, :type) @accepted = owner_class.am_field_option(@field, :accepted) # Recupero gli asset della risorsa, tramite ids passati come parametro o quelli associati direttamente ad essa ids = params[:ids] if ids @resource_assets = ((ids.length == 1 && ids[0] == 'no') ? [] : Asset.find_ordered(ids)) else @resource_assets = (@id ? Array(owner_class.find(@id).send(@field)) : []) end ids = @resource_assets.map(&:id) # Search params[:search][:asset_category_id_in].reject!(&:blank?) rescue nil params[:search][:file_type_in].reject!(&:blank?) rescue nil @search = AssetManager::Asset.(params[:search]) @assets = @search.relation @assets = @assets.not_ids(ids).public(@type).accepted(@accepted).send(Kaminari.config.page_method_name, params[Kaminari.config.param_name]).per(36).order(AssetManager::Asset.table_name + '.id DESC') @assets = @assets.tagged_with(params[:tags], any: true) unless params[:tags].nil? render layout: 'asset_manager/simple' end |
#show ⇒ Object
13 14 15 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 13 def show @asset = Asset.find(params[:id]) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/asset_manager/assets_controller.rb', line 40 def update @asset = Asset.find(params[:id]) if @asset.update_attributes(params[:asset]) redirect_to edit_asset_url(@asset), flash: { success: t('asset_manager.assets.controller.asset_successfully_update') } else @asset = build_translations(@asset) @asset = build_asset_instances(@asset) render action: 'edit' end end |