Add database support and model for tips

This commit is contained in:
Sebastian Serth
2020-10-07 17:42:44 +02:00
parent 85a05225ec
commit 2e1c97d87d
7 changed files with 101 additions and 1 deletions

23
app/models/tip.rb Normal file
View File

@@ -0,0 +1,23 @@
# frozen_string_literal: true
class Tip < ApplicationRecord
include Creation
has_many :exercise_tips
has_many :exercises, through: :exercise_tips
belongs_to :file_type, optional: true
validates_presence_of :file_type, if: :example?
validate :content?
def content?
errors.add :description, I18n.t('activerecord.errors.messages.at_least', attribute: I18n.t('activerecord.attributes.tip.example')) unless [description?, example?].include?(true)
end
def to_s
if title?
"#{I18n.t('activerecord.models.tip.one')}: #{title} (#{id})"
else
"#{I18n.t('activerecord.models.tip.one')} #{id}"
end
end
end