method
toggle
v1.2.6 -
Show latest stable
- Class:
ActiveRecord::Base
toggle(attribute)public
Turns an attribute that’s currently true into false and vice versa. 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)