Class: Golden::ActiveRecordForm

Inherits:
ApplicationForm show all
Defined in:
lib/golden/objects/form/active_record_form.rb

Constant Summary

Constants included from BooleanAccessor

BooleanAccessor::TRUE_VALUES

Instance Method Summary collapse

Methods inherited from ApplicationForm

attributes, permits

Methods included from DateTimeAccessor

#parse_time

Methods included from ExtendedAttrAccessor

#attributes, #strip_attributes, #strip_attributes!

Constructor Details

#initialize(params, accessors = {}) ⇒ ActiveRecordForm

Returns a new instance of ActiveRecordForm.



5
6
7
8
# File 'lib/golden/objects/form/active_record_form.rb', line 5

def initialize(params, accessors = {})
  assign_attributes(strip_attributes(params))
  assign_attributes(strip_attributes(accessors || {}))
end

Instance Method Details

#saveObject



10
11
12
13
14
15
16
17
# File 'lib/golden/objects/form/active_record_form.rb', line 10

def save
  return false if invalid?

  ::ActiveRecord::Base.transaction do
    run_callbacks(:save) { persist! }
  end
  errors.empty?
end