Multiple select list in rails

I have recently been tinkering with ruby on rails again and was banging my head against the wall with a multiple select list for a “has and belongs to many” relationship between models. After a lot of Googling and experimenting I finally got it running. The resulting code is deceptively simple!

This example illustrates the relationship between users and their roles. Each user can have multiple roles, and each role can have multiple users.

(more…)