Sha256: f73ad5cceea8bf60d3aa96ba0806eb5603c3215f26f0d3f53d698d10c67707b1
Contents?: true
Size: 954 Bytes
Versions: 26
Compression:
Stored size: 954 Bytes
Contents
module Mtwarden class Account < ActiveRecord::Base belongs_to :owner, :class_name => "Mtwarden::User" accepts_nested_attributes_for :owner belongs_to :plan, :class_name => "Mtwarden::Plan" validates :subdomain, :presence => true, :uniqueness => true validates :name, presence: true has_many :members, :class_name => "Mtwarden::Member" has_many :users, :through => :members EXCLUDED_SUBDOMAINS = %w(admin) validates_exclusion_of :subdomain, :in => EXCLUDED_SUBDOMAINS, :message => "is not allowed. Please choose another subdomain." validates_format_of :subdomain, :with => /\A[\w\-]+\Z/i, :message => "is not allowed. Please choose another subdomain." before_validation do self.subdomain = subdomain.to_s.downcase end def self.create_with_owner(params={}) account = new(params) if account.save account.users << account.owner end account end def owner?(user) owner == user end end end
Version data entries
26 entries across 26 versions & 1 rubygems