Module: UserProfileFormatter::ModelAdditions

Defined in:
lib/user_profile_formatter/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#format_user_profile(attribute, param = nil) ⇒ Object

Call format_user_profile in an Active Record model class to validate username of social media.

class Profile < ActiveRecord::Base
   :twitter
   :facebook
   :youtube
   :tumblr
   :goldenline
   :blip
end


17
18
19
20
21
22
23
# File 'lib/user_profile_formatter/model_additions.rb', line 17

def (attribute, param = nil)
  param = attribute if param.nil? and UserProfileFormatter.keys.include? attribute
  before_validation do
    send("#{attribute}=", UserProfileFormatter.(send(attribute), param))
  end
  validates_format_of attribute, with: UserProfileFormatter.format(param), message: "is not a valid"
end