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.416 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.407 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.396 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.395 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.393 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.388 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.385 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.382 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.374 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.372 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.368 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.366 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.357 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.354 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.351 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.350 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.349 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.344 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.343 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.339 lib/lalala/ext_active_record/assets.rb