Sha256: e934cf01868c1efbf526a8fd9daa05f7b3120ffbf565f56679575f7fadd5a4a1

Contents?: true

Size: 669 Bytes

Versions: 1

Compression:

Stored size: 669 Bytes

Contents

module AttrInitializable
  extend ActiveSupport::Concern

  module ClassMethods
    def attr_initializable(attributes, options = {})
      role = options.delete(:as) || :default
      initializable_attributes[role] ||= []
      initializable_attributes[role] += Array(attributes)
    end

    def initializable_attributes
      @@initializable_attributes ||= {}
    end
  end

  included do
  end

  def mass_assignment_authorizer(role = :default)
    accessible_attributes = super
    accessible_attributes += Array(self.class.initializable_attributes[role]) unless persisted?
    accessible_attributes
  end
end
 
ActiveRecord::Base.send :include, AttrInitializable

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attr_initializable-0.0.1 lib/attr_initializable.rb