Retrospring/app/models/profile.rb

32 lines
767 B
Ruby
Raw Normal View History

2021-12-19 07:51:04 -08:00
class Profile < ApplicationRecord
belongs_to :user
attr_readonly :user_id
validates :display_name, length: { maximum: 50 }
2021-12-19 07:51:04 -08:00
validates :location, length: { maximum: 72 }
validates :description, length: { maximum: 200 }
2021-12-19 07:51:04 -08:00
before_save do
unless website.blank?
self.website = if website.match %r{\Ahttps?://}
website
else
"http://#{website}"
end
end
end
def display_website
website.match(/https?:\/\/([A-Za-z.\-0-9]+)\/?(?:.*)/i)[1]
rescue NoMethodError
website
end
def safe_name
display_name.presence || user.screen_name
2021-12-19 07:51:04 -08:00
end
def question_length_limit = allow_long_questions ? nil : Question::SHORT_QUESTION_MAX_LENGTH
2021-12-19 07:51:04 -08:00
end