Forum: Ruby on Rails Conditional Validation: only if a record can be found

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Scott H. (Guest)
on 2009-05-23 20:55
Hello!

I have a guestlist page which lists tickets and a user can attache a
guest to each ticket by using an auto complete form.

If each ticket has a guest attached, then the guestlist is 'full'

I have this rule in my controller and I want to turn it into a
validation in the model. Any ideas?

(sudo code)

if Ticket.find(first, condition => guestlist_id = ? and guest_id IS
NILL)
    attach guest
else
    display 'guestlist is full'
end

Thanks for your help

Scott
This topic is locked and can not be replied to.