diff --git a/app/models/user.rb b/app/models/user.rb index 4bde2f4..44e7a41 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -141,9 +141,9 @@ def github_ruby_repositories_url def social_links links = {} - links[:website] = website if website.present? + links[:website] = ensure_protocol(website) if website.present? links[:twitter] = "https://twitter.com/#{twitter}" if twitter.present? - links[:linkedin] = linkedin if linkedin.present? + links[:linkedin] = ensure_protocol(linkedin) if linkedin.present? links[:github] = github_profile_url links end @@ -245,6 +245,10 @@ def self.linkify_bio(text) private + def ensure_protocol(url) + url.match?(%r{\A https?:// }x) ? url : "https://#{url}" + end + def precompute_bio_html self.bio_html = self.class.linkify_bio(bio) end