Skip to content

Instantly share code, notes, and snippets.

@the4dpatrick
Created March 18, 2014 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the4dpatrick/9629749 to your computer and use it in GitHub Desktop.
Save the4dpatrick/9629749 to your computer and use it in GitHub Desktop.
with_options
class User < ActiveRecord::Base
with_options if: :should_validate_password? do |user|
user.validates_presence_of :password
user.format_of :password, with: /^[^\s]+$/
end
attr_accessor :updating_password
def should_validate_password?
updating_password || new_record?
end
end
class Account < ActiveRecord::Baase
with_options dependent: :destroy do |acc|
acc.has_many :customers
acc.has_many :products
acc.has_many :invoices
acc.has_many :expenses
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment