Module: ActiveRecord::Acts::Toggleable

Extended by:
ActiveSupport::Concern
Defined in:
lib/acts_as_toggleable/active_record/acts/toggleable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#toggle(toggleable_attribute) ⇒ Object

Public: Toggle the attribute specified

Returns the value the attribute was changed to. Does not persist the change.



43
44
45
# File 'lib/acts_as_toggleable/active_record/acts/toggleable.rb', line 43

def toggle(toggleable_attribute)
  send("#{toggleable_attribute}=", !send(toggleable_attribute))
end

#toggle!(toggleable_attribute) ⇒ Object

Public: Toggle the attribute specified and persist the change

Returns the result of #save.



50
51
52
53
# File 'lib/acts_as_toggleable/active_record/acts/toggleable.rb', line 50

def toggle!(toggleable_attribute)
  toggle(toggleable_attribute)
  save
end