method
toggle
v2.1.0 -
Show latest stable
-
2 notes -
Class: ActiveRecord::Base
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (0)
- 2.0.3 (0)
- 2.1.0 (24)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
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.
Register or
log in
to add new notes.
tobago -
March 11, 2010
1 thank
Skips validations and callbacks
The method skips validations and callbacks. That is why it should be used with caution.
Code example
person.toggle :active
insane-dreamer -
April 12, 2009
0 thanks
Takes attribute as a symbol
Attribute must be passed as a symbol:
User.toggle(:funny)
not
User.toggle(funny)