views:

527

answers:

1

I'm going through the railscast no 73 (http://railscasts.com/episodes/73-complex-forms-part-1), where Ryan Bates explains how to use multiple models in a single form. He creates a project object, along with its tasks, in a single form (A simple app, where you create a project and its associated tasks)

It works well, but I'm not sure how to do validation. The normal validations like presence etc is easy to do. But, how to do duplicate task check? If we add validates_uniqueness_of, it will check against all tasks of all projects, whereas we would want to check for duplicate tasks only in the current project that is being created.

+1  A: 

What you want to do is:

validates_uniqueness_of :task_name, :scope => :project_id
Jaryl