Sha256: 11b7c4df457e61cde8f2d4be533faf2269866463c52ed621b43726d8af9e4eb8
Contents?: true
Size: 847 Bytes
Versions: 14
Compression:
Stored size: 847 Bytes
Contents
module Spree class Subscription < ActiveRecord::Base module RoleSubscriber extend ActiveSupport::Concern included do before_create :add_role_subscriber, :unless => :unsubscribed_at? before_update :remove_role_subscriber, :if => :unsubscribed_at? end def add_role_subscriber if role = subscriber_role user.spree_roles << role else errors.add :base, "Subscriber role is not present." false end end def remove_role_subscriber if role = subscriber_role user.spree_roles.destroy(role) else errors.add :base, "Subscriber role is not present." false end end private def subscriber_role Spree::Role.where(name: 'subscriber').first end end end end
Version data entries
14 entries across 14 versions & 1 rubygems