feature/share-libs
rb 39 lines 747 Bytes
Raw
1 class Lyric < ApplicationRecord
2 belongs_to :song
3 belongs_to :user
4
5 has_many :lyric_vote, dependent: :destroy
6 has_many :users, through: :lyric_vote
7
8 has_many :comments, as: :commentable
9
10 validates :lyric, presence: true
11
12 # Enum, enum everywhere...
13 enum status: [
14 :pending, # Freshly submitted.
15 :approved, # Approved by the community.
16 :deleted # To be deleted.
17 ]
18
19 def status_symbol
20 pending? ? 'bi-clock' : 'bi-check2-circle'
21 end
22
23 def status_color
24 pending? ? 'text-warning' : 'text-success'
25 end
26
27 def user_or_nowhereman
28 user || User.find_by(username: 'nowhereman')
29 end
30
31 def title_link
32 song.title_link
33 end
34
35 def slug
36 "#{song.slug}-#{id}"
37 end
38
39 end