2015-07-08 15:17:37 -04:00
|
|
|
class User < ActiveRecord::Base
|
2015-08-06 15:10:31 -04:00
|
|
|
extend FriendlyId
|
|
|
|
|
2015-07-08 15:17:37 -04:00
|
|
|
has_secure_password
|
|
|
|
|
2015-08-06 15:10:31 -04:00
|
|
|
has_many :comments
|
|
|
|
has_many :posts
|
|
|
|
|
|
|
|
friendly_id :username, use: :slugged
|
|
|
|
|
2015-07-08 15:17:37 -04:00
|
|
|
before_save :downcase_email
|
|
|
|
|
|
|
|
validates :email, presence: true, uniqueness: true
|
2015-08-06 15:10:31 -04:00
|
|
|
validates :username, presence: true, uniqueness: true, sluguuidless: true
|
2015-07-08 15:17:37 -04:00
|
|
|
validates :password, length: { minimum: 8 }
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def downcase_email
|
|
|
|
self.email = self.email.downcase
|
|
|
|
end
|
|
|
|
end
|