vendredi 8 janvier 2021

You have to wait 2 minutes to post. Multiple validates

The User has to wait 10 minutes to post again IF he:

  • PREVIOUSLY posted less then 2 minutes ago or
  • PREVIOUSLY posted a short comment (less then 20 characters) or
  • PREVIOUSLY posted the same text or
  • PREVIOUSLY posted a link.

in my models/comment.rb I added this

  scope :time_interval, -> { where('created_at > ?', 2.minutes.ago) }
  validate :check_probably_spam!

  def check_probably_spam!
    errors.add(
      :base, :check_probably_spam
    ) if (user.comments.time_interval.any?) || (...) ||  (...) ||  (...)
  end

I was able to made only the first task. Any tips to complete it?

The hardest part is to know how to have the previous comment.

Please, help me

Aucun commentaire:

Enregistrer un commentaire