Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card < ApplicationRecord
- validates :original_text, :translated_text,
- presence: true
- validate :check_texts_for_equality
- before_create :set_review_date
- scope :needs_review, -> {where('review_date <= ?', 3.days.ago).order('RANDOM()')}
- def check_translation
- self.original_text.downcase ==
- self.translated_text.downcase
- end
- def set_new_review_date
- if check_translation
- self.review_date = Time.now
- end
- end
- private
- def check_texts_for_equality
- if original_text.downcase.squish ==
- translated_text.downcase.squish
- errors.add(:original_text, message: "U Shell not Pass")
- end
- end
- def set_review_date
- self.review_date = 3.days.since
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement