Skip to content

Instantly share code, notes, and snippets.

@delba
Created June 5, 2013 20:04
Show Gist options
  • Select an option

  • Save delba/5716841 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5716841 to your computer and use it in GitHub Desktop.
one-line Active Record Callback
class User < ActiveRecord::Base
before_save(if: :username_changed?) { username.downcase! }
before_save 'username.downcase!', if: :username_changed?
before_save ->{ username.downcase! }, if: :username_changed?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment