I am following this post and trying to add a validate method before object creation. I keep getting undefined method 'video' for #<Video:0xbe430a0>
I am reading this article here http://ruby-for-beginners.rubymonstas.org/ getting to know how ruby works but cannot figure out why I get this error.
http://api.rubyonrails.org/v5.1/classes/ActiveModel/Validations/ClassMethods.html#method-i-validate
If I call new on a ruby object and save it with a validation what do I need to do to the video variable to not get undefined method
?
class Video < ApplicationRecord
validate :video_count_within_limit, on: :create
def video_count_within_limit
if video(:reload).count >= 9
errors.add(:base, "Exceeded video limit of 9 videos")
end
end