Module: ActivePostgrest::ActiveModelSupport

Included in:
Base
Defined in:
lib/active_postgrest/active_model.rb

Defined Under Namespace

Modules: SaveWithValidations

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
# File 'lib/active_postgrest/active_model.rb', line 9

def self.included(base)
  base.include ::ActiveModel::Validations
  base.extend  ::ActiveModel::Naming
  base.include ::ActiveModel::Conversion
  base.prepend SaveWithValidations
end

Instance Method Details

#read_attribute_for_validation(key) ⇒ Object



16
17
18
# File 'lib/active_postgrest/active_model.rb', line 16

def read_attribute_for_validation(key)
  @attributes[key.to_s]
end

#to_keyObject

Returns primary key value(s) for ActionView form helpers.



21
22
23
24
25
# File 'lib/active_postgrest/active_model.rb', line 21

def to_key
  pk = self.class.primary_key
  val = @attributes[pk]
  val ? [val] : nil
end