RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: bluebird-communication
I'm thinking about using HABTM instead of has_many because in my case, I do have a catalog of names (contributors) linked to a "groups" table.
Each "group" may have many "contributors" and each "contributor" may belong-to-many "groups". These two tables are linked with a "memberships" table.
As I don't want to waste my time with views, model, controller, routes, callbacks, bla-bla-bla for the "memberships" table, I just want to be able to set many contributors belonging to my group on my group form with a select-box. That is far more quicker to use the HABTM. (Now for validation, I just put a SQL table constraint UNIQUE index on both ID column of the membership table (in my migration) to avoid creating multiple same membership. This a protection against pirates, because a select box doesn't allow you to select multiple times the same item)
I think HABTM still make sens when you need to link one of your tables with a table (with a single column/attribute) that is just used as catalog of values. I may be wrong, but it makes sens to me.
As usual, this is a very handy example. However, I'm a bit confused. Why don't we need to use the "accept_nested_attributes_for" class method ?