Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Winton Welsh http://stu.dicio.us

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Custom Validation in ActiveRecord

// allows adding errors in methods other than validate

  def other_errors=(err)
    write_attribute(:other_errors,Array.new) if !self.other_errors
    self.other_errors[self.other_errors.length] = err
  end
        
  def other_errors
    read_attribute(:other_errors)
  end

  def validate
    if self.other_errors
      self.other_errors.each {|x| errors.add_to_base(x)}
      return
    end
    return if !errors.empty?
  end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed