Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/active_scaffold/extensions/unsaved_associated.rb,
lib/active_scaffold/extensions/unsaved_record.rb,
lib/active_scaffold/extensions/to_label.rb
Overview
the ever-useful to_label method
Instance Method Summary (collapse)
- - (Boolean) associated_valid?(path = [])
- - (Boolean) no_errors_in_associated?
- - (Object) save_associated
- - (Object) save_associated!
-
- (Object) save_with_unsaved_flag(*args)
automatically unsets the unsaved flag.
- - (Object) to_label
-
- (Object) unsaved=(val)
acts like a dirty? flag, manually thrown during update_record_from_params.
-
- (Boolean) unsaved?
whether the unsaved? flag has been thrown.
Instance Method Details
- (Boolean) associated_valid?(path = [])
3 4 5 6 7 8 |
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 3 def associated_valid?(path = []) return true if path.include?(self) # prevent recursion (if associated and parent are new records) path << self # using [].all? syntax to avoid a short-circuit with_unsaved_associated { |a| [a.valid?, a.associated_valid?(path)].all? {|v| v == true} } end |
- (Boolean) no_errors_in_associated?
18 19 20 |
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 18 def no_errors_in_associated? with_unsaved_associated {|a| a.errors.count == 0 and a.no_errors_in_associated?} end |
- (Object) save_associated
10 11 12 |
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 10 def save_associated with_unsaved_associated { |a| a.save and a.save_associated } end |
- (Object) save_associated!
14 15 16 |
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 14 def save_associated! save_associated or raise(ActiveRecord::RecordNotSaved) end |
- (Object) save_with_unsaved_flag(*args)
automatically unsets the unsaved flag
14 15 16 17 18 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 14 def save_with_unsaved_flag(*args) result = save_without_unsaved_flag(*args) self.unsaved = false return result end |
- (Object) to_label
3 4 5 6 7 |
# File 'lib/active_scaffold/extensions/to_label.rb', line 3 def to_label [:name, :label, :title, :to_s].each do |attribute| return send(attribute).to_s if respond_to?(attribute) end end |
- (Object) unsaved=(val)
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 |
- (Boolean) unsaved?
whether the unsaved? flag has been thrown
9 10 11 |
# File 'lib/active_scaffold/extensions/unsaved_record.rb', line 9 def unsaved? @unsaved end |