In terms of code support, although you can limit the number of categories that a user can select to 3 right now, you may not want to encode it with this restriction. You will kick yourself later when you want to increase it to 5 or decrease it to 1. My suggestion was to simply use has_and_belongs_to_many with a connection table (you don't need :through , because what I can tell you don't need from connection model, just a connection table). Using HABTM will automatically use the connection table, so you donβt have to worry about writing code to process it. Just make sure you name the connection table and its columns correctly.
Regarding the actual restriction of the user to only three categories, it is easy to implement this restriction in the view / controller (i.e., restrict the interface so that they cannot select more than 3).
I am sure you have already read this, but in case you have not done so, here are the docs for the HABTM.
Marc w
source share