Class: ContactDetails

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Faalis::Concerns::Authorizable
Defined in:
app/models/contact_details.rb

Instance Method Summary collapse

Instance Method Details

#validate_valueObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/contact_details.rb', line 15

def validate_value
  require 'json'
  if @already_validate
    return
  end

  if detail_field_id.nil?
    errors[:detail_field] = _("Field can not be empty.")
    return
  end
  rules = ContactField.find(detail_field_id).validation_rules
  unless rules.nil?
    params = JSON.parse(rules).deep_symbolize_keys
    @already_validate = true
    begin
      self.class.validates :detail_value, **params
    rescue ArgumentError => e
      errors[:error] = _("Field validation rules is not valid!")
    end
  else
    @already_validate = true
  end
end