A website template with lots of features, built with ruby on rails.

user.rb 976B

123456789101112131415161718192021222324252627282930313233343536
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :confirmable, :lockable, :timeoutable and :omniauthable
  4. devise :database_authenticatable, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable
  6. validates :password, presence: true, length: {minimum: 5, maximum: 120}, on: :create
  7. validates :password, length: {minimum: 5, maximum: 120}, on: :update, allow_blank: true
  8. has_many :posts
  9. mount_uploader :avatar, AvatarUploader
  10. def full_name
  11. name = self.first_name.to_s + ' ' + self.last_name.to_s
  12. return name
  13. end
  14. after_create do
  15. subscribe_user
  16. send_signup_mail
  17. end
  18. def subscribe_user
  19. if Subscription.find_by_email(self.email) == nil
  20. Subscription.create(first_name: self.first_name, last_name: self.last_name, email: self.email)
  21. end
  22. end
  23. def send_signup_mail
  24. UserMailer.signup_message(self).deliver
  25. end
  26. end