I’m quite new to this and I’m using cancan + devise for my user auth. However I’m not really sure what it means to set up a typical users HABTM roles relationship nor do I really understand what a HABTM relationship is.
Can anyone explain it really well or point me to a good tutorial or example?
HABTM means has and belongs to many. You basically need a table as a middle man to track multiple id’s (called a through table). When referenced as a typical users HABTM roles relationship, they really mean there would be a
Usermodel,Rolemodel, users table, roles table, and a roles_users table. Don’t forget to add the the HABTM — roles_users — table. A typical setup follows:You can then use the associations like normal saying
User.first.rolesandRole.first.users.There are also a couple Railscasts on your issues.