Module: ActsAsAssets::AssetsHelper

Included in:
AssetsController
Defined in:
app/helpers/acts_as_assets/assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_action(model) ⇒ Object



46
47
48
49
50
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 46

def asset_action(model)
  prefix = model.to_model.class.to_s.underscore.gsub(/\//, '_')
  method_name = "#{prefix}_create_asset_path".to_sym
  self.send(method_name, model, :type => @type, :format => :js)
end

#asset_file_name(asset) ⇒ Object



56
57
58
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 56

def asset_file_name(asset)
  File.basename(asset.asset.path)
end

#asset_file_path(asset) ⇒ Object



59
60
61
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 59

def asset_file_path(asset)
  asset.asset.url
end

#asset_id(model) ⇒ Object



52
53
54
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 52

def asset_id model
  asset_target model
end

#asset_labelObject



38
39
40
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 38

def asset_label
  defined?(type_label).nil? ? @type.split('/').last.to_s.humanize : type_label
end

#asset_target(model) ⇒ Object



10
11
12
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 10

def asset_target model
  @type.gsub(/\//, '_') + "_#{model.id.to_s.parameterize('_').gsub(/\-/, '_')}"
end

#assets_bodyObject



63
64
65
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 63

def assets_body
  j render(:partial => @asset_partial, :locals => {:assets => Array(@assets), :model => @model, read_only: false})
end

#destroy_file_path(asset, model) ⇒ Object



6
7
8
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 6

def destroy_file_path(asset, model)
  destroy_path(asset, model, asset_target(model), @type)
end


2
3
4
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 2

def destroy_link(asset, model)
  link_to(I18n.translate('destroy'), destroy_file_path(asset, model), {method: :delete, data: {:confirm => 'Sei Sicuro?'}, title: I18n.translate('destroy'), class: 'acts_as_assets_destroy', :remote => true})
end

#destroy_method_for(asset) ⇒ Object



18
19
20
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 18

def destroy_method_for(asset)
  "#{name_from(asset)}_destroy_asset_path".to_sym
end

#destroy_path(asset, model, target, type) ⇒ Object



14
15
16
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 14

def destroy_path(asset, model, target, type)
  send(destroy_method_for(asset), model, {:asset_id => asset.id, :target => target, :type => type})
end

#get_file_path(asset, model) ⇒ Object



22
23
24
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 22

def get_file_path(asset, model)
  get_path(asset, model, @type)
end

#get_method_for(asset) ⇒ Object



30
31
32
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 30

def get_method_for(asset)
  "#{name_from(asset)}_get_asset_path".to_sym
end

#get_path(asset, model, type) ⇒ Object



26
27
28
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 26

def get_path(asset, model, type)
  send(get_method_for(asset), model.to_model, asset, {:asset_id => asset.id, :type => type})
end

#name_from(asset) ⇒ Object



34
35
36
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 34

def name_from(asset)
  asset.class.base_model_sym
end

#upload_complete_js_function(model) ⇒ Object



42
43
44
# File 'app/helpers/acts_as_assets/assets_helper.rb', line 42

def upload_complete_js_function model
  "function(id, fileName, responseJSON, qq){K.allegati.onComplete(id, fileName, responseJSON, qq,'#{asset_action(model)}');}"
end