Question

I have a form for Library, which has several nested objects for Librarian. My question is:

How can I validate uniqueness of Librarian's name? (there may be multiple librarians for one library, but there should not be the same librarian appears twice). I found a hint but couldn't make it work:

    validates_uniqueness_of :task_name, :scope => :project_id

Please give me an example, because I found pieces to the puzzle but have not been able to put them together.

Était-ce utile?

La solution

If Librarian has library_id:

validates_uniqueness_of :name, :scope => :library_id
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top