Model Verification

Why does this not work?
validate :must_exist

def must_exist
for team in Team.find(:all)
errors.add_to_base(“Team must exist. Maybe invite them to
register?”) unless opponent == and home !=

On 15 Apr 2008, at 16:54, edberner wrote:

I think it doesn’t work because the logic in the lines above is just
fundamentally broken (I can’t make head or tail of what it’s trying to

say opponent is team C and home is team B, and that you have teams A,
B, C (and assume find :all returns them in that order).

then on that first iteration you get

errors.add_to_base(…) unless C == A and B != A, which is of course
enough to trigger add_to_base.

This would also be horrific if there were lots of teams. From the name
of your method, don’t you mean

errors.add_to_base(…) if Team.find_by_name(opponent).nil? ||


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs