Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created November 22, 2011 11:45
Show Gist options
  • Save joeljunstrom/1385487 to your computer and use it in GitHub Desktop.
Save joeljunstrom/1385487 to your computer and use it in GitHub Desktop.
before_save :hash_new_key, :if => :key_not_blank?
def key_not_blank?
!self.key.blank?
end
before_save :hash_new_key, :unless => :no_key?
def no_key?
self.key.blank?
end
before_save :hash_new_key, :if => :has_key?
def has_key?
self.key.present?
end
# Imho bättre för enklare saker
before_save :hash_new_key, :if => Proc.new { |a| a.key.present? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment