Greetings -
I’m trying to find the most efficient, “Rails” way to solve the
following problem. It’s in two parts, but I think the solution is
somewhat related:
I have Recipe and Category model related by HABTM. I would like to
1.) Validate the number of categories associated with a recipe, say a
minimum of 1 and a max of 3. (So validates_associated will not work
here, right?)
2.) In the view, present a select box with a prompt in it, e.g. “Choose
1 to 3 of the following categories”, as the first option. I’ve found
ways to get this to work with the :prompt method in a 1-to-many
relationship, but I haven’t found anything to work with a HABTM
I’ve solved #1 with a controller hack that feeds the number categories
to a recipe accessor and then validating that, but that seems so …
wrong.
Any suggestions, pointers?
TIA!