Skip to content

Commit

Permalink
prevent mass assignment on subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Carpenter committed Sep 2, 2011
1 parent c108b80 commit daed70a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/models/subscription.rb
Expand Up @@ -18,6 +18,7 @@
=end Schema Information

class Subscription < ApplicationModel
attr_accessible :email, :search_conditions
default_scope :conditions => { :environment => Rails.env }
before_create :generate_token
after_create :ask_for_confirmation
Expand Down Expand Up @@ -57,11 +58,18 @@ def was_active?
end

def confirm!
self.update_attributes!(:confirmed_at => Time.current, :unsubscribed_at => nil) unless self.active?
unless active?
self.confirmed_at = Time.current
self.unsubscribed_at = nil
self.save!
end
end

def unsubscribe!
self.update_attributes!(:unsubscribed_at => Time.current) unless self.unsubscribed_at
unless self.unsubscribed_at
self.unsubscribed_at = Time.current
self.save!
end
Mailer.deliver_unsubscribe_notice(self)
end

Expand Down

0 comments on commit daed70a

Please sign in to comment.