class Meme < ApplicationRecord
  belongs_to :user
  has_one_attached :file

  has_many :votes, dependent: :destroy

  validates :slot, presence: true
  validates_inclusion_of :slot, in: 1..16

  def file_url
    if file.attached?
      Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true)
    end
  end

  def vote_count
    votes.count
  end
end
