class Submission < ActiveRecord::Base
#Set up how the model works
belongs_to :contest
belongs_to :subject
#Validate the field we're talking about in this post:
validates_presence_of :subject_id,
:on => :create,
:if => :needs_subject?
.. And later I defined needs_subject? as follows:
def needs_subject?
if self.contest.subjects.any?
return true
else
return false
end
end
end #End the model.
So this allowed me to only check if there's a subject if there SHOULD BE a subject.
Hope this helps someone.
~Nic
No comments:
Post a Comment