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.201 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.198 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.195 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.194 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.193 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.192 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.191 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.190 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.189 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.188 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.187 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.186 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.185 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.184 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.183 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.181 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.180 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.179 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.178 lib/lalala/ext_active_record/assets.rb
lalala-4.0.0.dev.177 lib/lalala/ext_active_record/assets.rb