Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update_attribute is gone in Rails 4, add update_column support. #25

Merged
merged 1 commit into from

2 participants

Erich Menge Ryan Bigg
Erich Menge

update_attribute is deprecated in Rails > 3.2.6. Use update_column if available.

Ryan Bigg radar merged commit ef8b1f4 into from
Ryan Bigg
Owner

:heart:

Erich Menge erichmenge deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 26, 2012
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/paranoia.rb
15 lib/paranoia.rb
View
@@ -17,19 +17,26 @@ def destroy
_run_destroy_callbacks { delete }
end
- def delete
- self.update_attribute(:deleted_at, Time.now) if !deleted? && persisted?
+ def delete
+ update_attribute_or_column(:deleted_at, Time.now) if !deleted? && persisted?
freeze
end
-
+
def restore!
- update_attribute :deleted_at, nil
+ update_attribute_or_column :deleted_at, nil
end
def destroyed?
!self.deleted_at.nil?
end
alias :deleted? :destroyed?
+
+ private
+
+ # Rails 3.1 adds update_column. Rails > 3.2.6 deprecates update_attribute, gone in Rails 4.
+ def update_attribute_or_column(*args)
+ respond_to?(:update_column) ? update_column(*args) : update_attribute(*args)
+ end
end
class ActiveRecord::Base
Something went wrong with that request. Please try again.