0

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.

AdamNYC
  • 19,887
  • 29
  • 98
  • 154

1 Answers1

0

If Librarian has library_id:

validates_uniqueness_of :name, :scope => :library_id
Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77
  • Hi nash, are you saying that by default, Library has access to :name attribute of Librarian? I did this in libraries_controller but I got error saying name is undefined. – AdamNYC Nov 12 '11 at 17:21
  • Stop, why do you do it in libraries_controller? You should put it in the Librarian model. It would be helpful if you show us your models. – Vasiliy Ermolovich Nov 12 '11 at 17:26
  • Hi nash, sorry, I am doing it in model but got the error saying name is undefined. – AdamNYC Nov 13 '11 at 16:36