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