Class: 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
- #associated_valid?(path = []) ⇒ Boolean
- #no_errors_in_associated? ⇒ Boolean
- #save_associated ⇒ Object
- #save_associated! ⇒ Object
-
#save_with_unsaved_flag(*args) ⇒ Object
automatically unsets the unsaved flag.
- #to_label ⇒ Object
-
#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
#associated_valid?(path = []) ⇒ Boolean
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 |
#no_errors_in_associated? ⇒ Boolean
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 |
#save_associated ⇒ Object
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 |
#save_associated! ⇒ Object
14 15 16 |
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 14 def save_associated! save_associated or raise(ActiveRecord::RecordNotSaved) end |
#save_with_unsaved_flag(*args) ⇒ Object
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 |
#to_label ⇒ Object
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 |
#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 |