rails boolean fields: `is_foo` or just `foo`?

Ruby on-RailsConvention

Ruby on-Rails Problem Overview


> Possible Duplicate:
> Naming Boolean columns in Rails

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?.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Solution 2 - Ruby on-Rails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkikitoView Question on Stackoverflow
Solution 1 - Ruby on-RailsChuckView Answer on Stackoverflow
Solution 2 - Ruby on-RailsallesklarView Answer on Stackoverflow