method
toggle
v2.2.1 -
Show latest stable
- Class:
ActiveRecord::Base
toggle(attribute)public
Assigns to attribute the boolean opposite of attribute?. So if the predicate returns true the attribute will become false. This method toggles directly the underlying value without calling any setter. Returns self.
2Notes
Skips validations and callbacks
The method skips validations and callbacks. That is why it should be used with caution.
==== Code example
person.toggle :active
Takes attribute as a symbol
Attribute must be passed as a symbol:
User.toggle(:funny)
not
User.toggle(funny)