Sha256: 4ae42cab4abe1bd82d3df627e356fc83b2096412b0d0597fcc1ef556a669f550

Contents?: true

Size: 530 Bytes

Versions: 9

Compression:

Stored size: 530 Bytes

Contents

class ForumSubscription < ApplicationRecord
  belongs_to :forum_thread
  belongs_to :user

  scope :optin, ->{ where(subscription_type: :optin) }
  scope :optout, ->{ where(subscription_type: :optout) }

  validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
  validates :user_id, uniqueness: { scope: :forum_thread_id }

  def toggle!
    case subscription_type
    when "optin"
      update(subscription_type: "optout")
    when "optout"
      update(subscription_type: "optin")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
simple_discussion-1.2.0 app/models/forum_subscription.rb
simple_discussion-1.0.1 app/models/forum_subscription.rb
simple_discussion-1.0.0 app/models/forum_subscription.rb
simple_discussion-0.9.5 app/models/forum_subscription.rb
simple_discussion-0.9.4 app/models/forum_subscription.rb
simple_discussion-0.9.3 app/models/forum_subscription.rb
simple_discussion-0.9.2 app/models/forum_subscription.rb
simple_discussion-0.9.1 app/models/forum_subscription.rb
simple_discussion-0.9.0 app/models/forum_subscription.rb