method

toggle

rails latest stable - Class: ActiveRecord::Base

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

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

tobago · Mar 11, 20101 thank

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

insane-dreamer · Apr 11, 2009

Attribute must be passed as a symbol:

User.toggle(:funny)

not

User.toggle(funny)