Module: ActiveScaffold::UnsavedRecord
- Defined in:
- lib/active_scaffold/extensions/unsaved_record.rb
Overview
a simple (manual) unsaved? flag and method. at least it automatically reverts after a save!
Instance Method Summary collapse
- #keeping_errors ⇒ Object
-
#save ⇒ Object
automatically unsets the unsaved flag.
-
#unsaved=(val) ⇒ Object
acts like a dirty? flag, manually thrown during update_record_from_params.
-
#unsaved? ⇒ Boolean
whether the unsaved? flag has been thrown.
Instance Method Details
#keeping_errors ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 18 def keeping_errors old_errors = errors.dup if errors.present? result = yield old_errors&.each do |attr| old_errors[attr].each { |msg| errors.add(attr, msg) unless errors.added?(attr, msg) } end result && old_errors.blank? end |
#save ⇒ Object
automatically unsets the unsaved flag
14 15 16 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 14 def save(*) super.tap { self.unsaved = false } end |
#unsaved=(val) ⇒ Object
acts like a dirty? flag, manually thrown during update_record_from_params.
4 5 6 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 4 def unsaved=(val) @unsaved = val ? true : false end |
#unsaved? ⇒ Boolean
whether the unsaved? flag has been thrown
9 10 11 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 9 def unsaved? @unsaved end |