Results 1 to 3 of 3
Jul 18, 2006, 04:03 #1
- Join Date
- Mar 2001
- North Wales, UK
- 0 Post(s)
- 0 Thread(s)
Rails - "at least one" in a HABTM relationship
I have products and categories, and a has_and_belongs_to_many relationship so that products can be in multiple categories. When adding a product, I want to ensure that the user selects at least one of the categories from the list.
How do I go about this? I'm unsure whether it's something I have to specify in the relationship itself, or if it's something I can do using validates_presence_of in some way.
Hopefully someone can point me in the right direction!