Sha256: c3ade7acc959de8a3cf884497a8ab31d82851a765d1e5c6e97fd0c4079e7abbd

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

module Mtdevise
  class Account < ActiveRecord::Base
  
    # Relationships
    belongs_to :owner, :class_name => "Mtdevise::User"
    has_many :members, :class_name => "Mtdevise::Member"
    has_many :users, :through => :members
    
    accepts_nested_attributes_for :owner
    
    # Form Validations
    validates :subdomain,
      presence: true,
      uniqueness: true,
      format: { with: /\A[\w\-]+\Z/i, message: 'is not allowed. Please choose another subdomain.'},
      exclusion: { in: %w(admin), message: 'is not allowed. Please choose another subdomain.'}
    
    validates :name,
    presence: true,
      uniqueness: {scope: :owner_id}
    
    validates :firstname,
      presence: true
    
    validates :lastname,
      presence: true
    
    validates :username,
      presence: true,
      uniqueness: true
    
    before_validation do
      self.subdomain = subdomain.to_s.downcase
      self.username = username.to_s.downcase
    end
    
    # Define Account/Owner for User
    def self.create_with_owner(params={})
      account = new(params)
      if account.save
        account.users << account.owner
        account.owner.confirm
      end
      account
    end
  
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mtdevise-3.10.1 app/models/mtdevise/account.rb
mtdevise-3.10.0 app/models/mtdevise/account.rb
mtdevise-3.9.1 app/models/mtdevise/account.rb
mtdevise-3.9.0 app/models/mtdevise/account.rb