Module: HasCredentialModelHelper

Included in:
ClientRepresentative, Employee
Defined in:
app/helpers/has_credential_model_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/has_credential_model_helper.rb', line 26

def self.append_features(base)
  super

  base.class_eval do
    has_one :credential, :as => :user, :dependent => :destroy
    
    after_save :credential_after_save
    
    
    alias validate_without_credentials validate
    alias validate validate_credential_fields
  end
end

Instance Method Details

#credential_after_saveObject



17
18
19
# File 'app/helpers/has_credential_model_helper.rb', line 17

def credential_after_save
  credential.save! if credential.changed?
end

#validate_credential_fieldsObject



21
22
23
24
# File 'app/helpers/has_credential_model_helper.rb', line 21

def validate_credential_fields
  credential.errors.each{|attr,msg| errors.add attr, msg } unless credential.valid?
  validate_without_credentials
end