Module: SecureFields

Extended by:
ActiveSupport::Concern
Defined in:
lib/app/models/concerns/secure_fields.rb

Overview

A mixin for models with secure fields. Basically if the secure field is blank, nil or “”, then delete it from the update.

Instance Method Summary collapse

Instance Method Details

#assign_attributes(params) ⇒ Object

Remove updates for secure fields



26
27
28
# File 'lib/app/models/concerns/secure_fields.rb', line 26

def assign_attributes(params)
  super(filter_secure_fields(params))
end

#filter_secure_fields(params) ⇒ Object



37
38
39
40
# File 'lib/app/models/concerns/secure_fields.rb', line 37

def filter_secure_fields(params)
  secure_fields.each { |field| params.delete(field) if params[field].blank? }
  params
end

#secure_fieldsObject

List of secure fields



33
34
35
# File 'lib/app/models/concerns/secure_fields.rb', line 33

def secure_fields
  []
end

#update(params) ⇒ Object

Remove updates for secure fields



12
13
14
# File 'lib/app/models/concerns/secure_fields.rb', line 12

def update(params)
  super(filter_secure_fields(params))
end

#update!(params) ⇒ Object

Remove updates for secure fields



19
20
21
# File 'lib/app/models/concerns/secure_fields.rb', line 19

def update!(params)
  super(filter_secure_fields(params))
end