views:

43

answers:

2

What is the rails convention regarding names of boolean fields?

For example, if I have a User model that needs a flag for its "activeness", should I call the db field is_active or active ?

Note: Rails automatically generates question-marked methods for accessing boolean fields: User.is_active? and User.active?.

+1  A: 

Of the 2 you should choose the one that sounds better to you: User.active? or User.is_active?

I'd personally opt for the former.

The question mark goody comes from Ruby, not Rails.

allesklar
Your gave me the solution to my problem - I ended up using what I thought was most correct (`is_client`). Chuck however answered the question - Rails (and Ruby) seem to favour the plain-adjective. I would share the answer between the two of you if I could. I can only give you a +1 and my thanks. Also, thanks for the pointers regarding the question mark - I didn't know it came from ruby itself.
egarcia
+2  A: 

The plain-adjective form is easily the norm in Ruby and Rails — even?, nil?, empty? and blank? for example. The only method of the form is_#{something}? that I can think of is Kernel#is_a? to determine class identity. So to stick with standard naming conventions, I would leave off the is_ on boolean methods like this.

Chuck
thanks I appreciate your comment. However I believe `is_xxx` will be more appropiate for my application. I've run up to a boolean called `is_client`. Replacing it by `client` makes it look like an ActiveRecord association (eventhough I don't have a Client model on my design... for now).
egarcia