Sha256: 953f3fa1f760242cdba5e1f4493780cdd46f84af19fcce2d6eb6fe1f2f3bd630
Contents?: true
Size: 953 Bytes
Versions: 26
Compression:
Stored size: 953 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