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

Direct Known Subclasses

ActiveScaffold::Tableless

Instance Method Summary collapse

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? }
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_associatedObject



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

#to_labelObject



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