Module: UserProfileFormatter::ModelAdditions
- Defined in:
- lib/user_profile_formatter/model_additions.rb
Instance Method Summary collapse
-
#format_user_profile(attribute, param = nil) ⇒ Object
Call
format_user_profile
in an Active Record model class to validate username of social media.
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
format_user_profile :twitter
format_user_profile :facebook
format_user_profile :youtube
format_user_profile :tumblr
format_user_profile :goldenline
format_user_profile :blip
end
17 18 19 20 21 22 23 |
# File 'lib/user_profile_formatter/model_additions.rb', line 17 def format_user_profile(attribute, param = nil) param = attribute if param.nil? and UserProfileFormatter.keys.include? attribute before_validation do send("#{attribute}=", UserProfileFormatter.format_user_profile(send(attribute), param)) end validates_format_of attribute, with: UserProfileFormatter.format(param), message: "is not a valid" end |