/
Infernocasis
/
X.com
Обзор
Документация
Войти
/
Infernocasis
/
X.com
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/models/user.rb
25 строк
932 B
Infernocasis
Initial commit
08 июн 2025, 20:43
08 июн 2025, 20:43
68371ab
Код
Авторство
О чём код?
class User < ApplicationRecord has_secure_password has_many :posts, dependent: :destroy has_many :likes, dependent: :destroy has_many :retweets, dependent: :destroy has_many :liked_posts, through: :likes, source: :post has_many :retweeted_posts, through: :retweets, source: :post validates :username, presence: true, uniqueness: true, length: { minimum: 3, maximum: 20 } validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } validates :password, presence: true, length: { minimum: 6 }, allow_nil: true validates :bio, length: { maximum: 160 } before_save :set_default_values private def set_default_values self.followers_count ||= 0 self.following_count ||= 0 self.avatar_url ||= "https://abs.twimg.com/sticky/default_profile_images/default_profile_400x400.png" self.cover_url ||= "https://abs.twimg.com/images/themes/theme1/bg.png" end end