Sha256: cbd544a17ad0298c46274bf6c31f720d5696075762a6adacb25121e29ee376ab

Contents?: true

Size: 964 Bytes

Versions: 116

Compression:

Stored size: 964 Bytes

Contents

module Lalala::ExtActiveRecord::Assets
  extend ActiveSupport::Concern

  module ClassMethods

    def has_many_assets(name, options={})
      class_name = options.delete(:class_name)
      class_name ||= if name.to_s.include?("image") then "::ImageAsset" else "::FileAsset" end

      attr_accessible :"#{name}_attributes"
      has_many name, class_name: class_name, as: :asset_owner, dependent: :destroy, conditions: { asset_owner_section: name.to_s }
      accepts_nested_attributes_for name, allow_destroy: true
    end

    def has_one_asset(name, options={})
      class_name = options.delete(:class_name)
      class_name ||= if name.to_s.include?("image") then "::ImageAsset" else "::FileAsset" end

      attr_accessible :"#{name}_attributes"
      has_one name, class_name: class_name, as: :asset_owner, dependent: :destroy, conditions: { asset_owner_section: name.to_s }
      accepts_nested_attributes_for name, allow_destroy: true
    end

  end
end

Version data entries

116 entries across 116 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.133 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.132 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.131 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.129 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.128 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.126 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.125 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.124 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.123 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.118 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.116 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.114 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.113 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.111 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.109 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.107 lib/lalala/ext_active_record/assets.rb