Class: ActiveRecord::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/active_scaffold/extensions/unsaved_associated.rb,
lib/active_scaffold/extensions/to_label.rb
Overview
the ever-useful to_label method
Instance Method Summary
collapse
Instance Method Details
#associated_valid?(path = []) ⇒ Boolean
3
4
5
6
7
8
9
10
|
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 3
def associated_valid?(path = [])
return true if path.include?(self)
path << self
with_unsaved_associated { |a| [a.keeping_errors { a.valid? }, a.associated_valid?(path)].all? }
end
|
#no_errors_in_associated? ⇒ Boolean
20
21
22
|
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 20
def no_errors_in_associated?
with_unsaved_associated { |a| a.errors.count.zero? && a.no_errors_in_associated? }
end
|
#save_associated ⇒ Object
12
13
14
|
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 12
def save_associated
with_unsaved_associated { |a| a.save && a.save_associated }
end
|
#save_associated! ⇒ Object
16
17
18
|
# File 'lib/active_scaffold/extensions/unsaved_associated.rb', line 16
def save_associated!
save_associated || raise(ActiveRecord::RecordNotSaved, "Fail saving associations for #{inspect}")
end
|
3
4
5
6
7
8
|
# File 'lib/active_scaffold/extensions/to_label.rb', line 3
def to_label
to_label_method = ActiveScaffold::Registry.cache :to_label, self.class.name do
%i[name label title to_s].find { |attribute| respond_to?(attribute) }
end
send(to_label_method).to_s if to_label_method
end
|