app/models/mtdevise/account.rb in mtdevise-2.5.0 vs app/models/mtdevise/account.rb in mtdevise-2.5.2
- old
+ new
@@ -1,13 +1,16 @@
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.'}
@@ -29,16 +32,17 @@
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
\ No newline at end of file
+end