Skip to content

Instantly share code, notes, and snippets.

@aflag
Last active December 12, 2015 13:39
Show Gist options
  • Save aflag/4780225 to your computer and use it in GitHub Desktop.
Save aflag/4780225 to your computer and use it in GitHub Desktop.
class Lawyer < ActiveRecord::Base
def extracted?
!source.blank?
end
with_options :unless => :extracted? do |lawyer|
lawyer.validates_presence_of :oab,
:phones,
:address,
:day_of_birth,
:email
lawyer.validates_associated :phones,
:address,
:nextels,
:cities
end
end
l = Lawyer.new
l.source = "whatever"
l.valid? # returns true
l.address = Address.new
l.valid? # returns false
l.save validate:false
l.reload
l.valid? # returns true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment