Class setup ---------------
Methods
- A
- E
- N
- T
- V
Class Public methods
Using
Source: show
# File rails/activerecord/examples/validation.rb, line 20 def self.authenticate(name, pass) # find_first "name = '#{name}' AND pass = '#{pass}'" would be open to sql-injection (in a web-app scenario) find_first [ "name = '%s' AND pass = '%s'", name, pass ] end
Source: show
# File rails/activerecord/examples/validation.rb, line 25 def self.name_exists?(name, id = nil) if id.nil? condition = [ "name = '%s'", name ] else # Check if anyone else than the person identified by person_id has that user_name condition = [ "name = '%s' AND id <> %d", name, id ] end !find_first(condition).nil? end
Source: show
# File rails/activerecord/examples/associations.rb, line 39 def self.table_name() "people" end
Instance Public methods
Source: show
# File rails/activerecord/examples/validation.rb, line 36 def email_address_with_name "\"#{name}\" <#{email}>" end
Instance Protected methods
Source: show
# File rails/activerecord/examples/validation.rb, line 41 def validate errors.add_on_empty(%w(name pass email)) errors.add("email", "must be valid") unless email_address_valid? end
Source: show
# File rails/activerecord/examples/validation.rb, line 46 def validate_on_create if attribute_present?("name") && Person.name_exists?(name) errors.add("name", "is already taken by another person") end end
Source: show
# File rails/activerecord/examples/validation.rb, line 52 def validate_on_update if attribute_present?("name") && Person.name_exists?(name, id) errors.add("name", "is already taken by another person") end end