Users, Roles, and naming the join model

By Lachlan Sylvester

I recently was working on some code for a security model. It was pretty standard, with Users and Roles and lots of other stuff that felt like overkill.

I hit a bit of a stubbing block when it came to naming my join model. A user has many roles through what??

In the end I copied my database and went with privileges. The result was

class User
  has_many :privileges
  has_many :roles, :through => :privileges
class Privilege
  belongs_to :role
  belongs_to :user
class Role
  has_many :privileges
  has_many :users, :through => :privileges

I find that coming up with good names that accurately reflect the intent as one of the biggest programming challenges.

It also got me thinking about how to model responsibilities, even though they they weren’t needed is this particular case. I think that it would be something like:

class User
  has_many :great_powers, :conditions => {:great => true}
  has_many :great_responsibilities, :through => :great_powers
| More
All tags

The Hypothetical Blog: Stark Raving Sane

April 05 Icons, icons and icons!

Building any kind of web interface, particularly one that requires any kind of human interactivity, will at some time utilise icons. Whether they be on buttons, used in headings, or tabs or panels, icons are like little visual pieces of informative haiku: small, succint and should make you smile.

more »

What We're Reading


In our opinion, Ryan Bates is something of a Rails stevedore: since March of 2007 he’s been packaging and delivering Railscasts to the interwebs on a weekly basis.

Available through iTunes or via download on the Railscast website, each episode lasts between five and twenty minutes, with shownotes and additional resources also available on the website.

more »