Skip to content

Instantly share code, notes, and snippets.

@jurikern
Created August 23, 2012 10:07
Show Gist options
  • Save jurikern/3435077 to your computer and use it in GitHub Desktop.
Save jurikern/3435077 to your computer and use it in GitHub Desktop.
Validation using :if or :unless conditions
class EmploymentInformation < ActiveRecord::Base
attr_accessible :employment_status_id, :company_name, :university
validates :employment_status_id, :presence => true, :inclusion => { :in => proc { |req| req.employment_status_types.map{ |key, value| key } } }
validates :company_name, :presence => true, :format => { :with => /\A[A-z\s\-\._]+\z/ }, :unless => proc { |req| req.employment_status.nil? }
validates :university, :presence => true, :format => { :with => /\A[A-z\s\-\._]+\z/ }, :unless => proc { |req| req.employment_status.nil? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment