I got the following snippet
Class Artist < ActiveRecord
attr_accessible :solo #boolean
def change_solo!
if self.solo == false
self.solo = true
else
self.solo = false
end
self.save
end
end
Is there a better way to write that? Thanks in advance cheers tabaluga
Don't write this method. Use ActiveRecord::Base#toggle! instead:
artist_object.toggle!(:solo)
This method also exists in Rails 2, if you haven't upgraded yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With