Sha256: c1c28ec19c75f69aa2d8965e3f48cb544549fbdbde1502dffbd66baa1bfc6181

Contents?: true

Size: 786 Bytes

Versions: 23

Compression:

Stored size: 786 Bytes

Contents

# a simple (manual) unsaved? flag and method. at least it automatically reverts after a save!
module ActiveScaffold::UnsavedRecord
  # acts like a dirty? flag, manually thrown during update_record_from_params.
  def unsaved=(val)
    @unsaved = val ? true : false
  end

  # whether the unsaved? flag has been thrown
  def unsaved?
    @unsaved
  end

  # automatically unsets the unsaved flag
  def save(*)
    super.tap { self.unsaved = false }
  end

  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
end
ActiveRecord::Base.class_eval { include ActiveScaffold::UnsavedRecord }

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
active_scaffold-3.6.20 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.19 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.17 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.15 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.14 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.13 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.12 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.11.1 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.11 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.10 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.9 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.8 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.6 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.5 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.4.1 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.4 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.3 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.2 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.1 lib/active_scaffold/extensions/unsaved_record.rb
active_scaffold-3.6.0 lib/active_scaffold/extensions/unsaved_record.rb