Skip to content

Instantly share code, notes, and snippets.

@pschyska
Created September 5, 2013 10:18
Show Gist options
  • Save pschyska/6448376 to your computer and use it in GitHub Desktop.
Save pschyska/6448376 to your computer and use it in GitHub Desktop.
class TierMembership < ActiveRecord::Base
attr_accessible :tier, :user
belongs_to :tier
belongs_to :user
validates :user_id, presence: true
validates :tier_id, presence: true, uniqueness: { scope: :user_id }
validate :valid_user_role
def valid_user_role
unless user.blank? || ["agent", "admin"].include?(user.account.role)
errors.add(:user, "must be agent or admin")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment