Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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