Module: ActsAsAssets::ClassMethods
- Defined in:
- lib/acts_as_assets/base.rb
Instance Method Summary collapse
- #acts_as_assets(*args) ⇒ Object
- #path_with_styles ⇒ Object
- #path_without_styles ⇒ Object
- #url_with_styles(download_prefix) ⇒ Object
- #url_without_styles(download_prefix) ⇒ Object
Instance Method Details
#acts_as_assets(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/acts_as_assets/base.rb', line 18 def acts_as_assets *args cattr_accessor :foreign_key_name cattr_accessor :base_model_name cattr_accessor :base_model cattr_accessor :download_prefix cattr_accessor :base_model_sym include InstanceMethods = args. raise "Class #{self} must specify a :base_model option" if [:base_model].nil? self.base_model = [:base_model].to_s.camelize.constantize self.base_model_name = base_model.to_s.underscore self.base_model_sym = base_model_name.gsub(/\//, '_').to_sym self.foreign_key_name = ([:foreign_key] || "#{base_model_name}_id").to_sym self.download_prefix = [:download_prefix] || base_model_name.to_s.pluralize belongs_to base_model_sym, foreign_key: foreign_key_name, class_name: base_model.to_s paperclip_config = { :url => .include?(:styles) ? url_with_styles(download_prefix) : url_without_styles(download_prefix), :path => .include?(:styles) ? path_with_styles : path_without_styles } has_attached_file :asset, paperclip_config.merge() before_create :increment_counter end |
#path_with_styles ⇒ Object
58 59 60 |
# File 'lib/acts_as_assets/base.rb', line 58 def path_with_styles ":acts_as_assets_file_path/:style/:acts_as_assets_file_name.:extension" end |
#path_without_styles ⇒ Object
62 63 64 |
# File 'lib/acts_as_assets/base.rb', line 62 def path_without_styles ":acts_as_assets_file_path/:acts_as_assets_file_name.:extension" end |
#url_with_styles(download_prefix) ⇒ Object
50 51 52 |
# File 'lib/acts_as_assets/base.rb', line 50 def url_with_styles(download_prefix) "/#{download_prefix}/:acts_as_assets_root_id/assets/get/:acts_as_assets_asset_id/:style/:acts_as_assets_file_name.:extension?type=:acts_as_assets_type" end |
#url_without_styles(download_prefix) ⇒ Object
54 55 56 |
# File 'lib/acts_as_assets/base.rb', line 54 def url_without_styles(download_prefix) "/#{download_prefix}/:acts_as_assets_root_id/assets/get/:acts_as_assets_asset_id/:acts_as_assets_file_name.:extension?type=:acts_as_assets_type" end |