You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

18 lines
372 B

  1. class Post < ApplicationRecord
  2. belongs_to :thread, class_name: 'Topic', foreign_key: :thread_id
  3. has_one_attached :image
  4. before_create :set_post_no
  5. has_secure_password validations: false
  6. scope :active, -> { where deleted_at: nil }
  7. private
  8. def set_post_no
  9. max_no = Post.where(thread_id:).maximum(:post_no) || 0
  10. self.post_no = max_no + 1
  11. end
  12. end