Using question mark character in Rails/ActiveRecord column name

at. picture at. · Sep 24, 2012 · Viewed 12.6k times · Source

In keeping with Ruby's idiom of using a question mark in boolean methods (e.g. person.is_smart?), I'd like to do the same for an ActiveRecord field in Rails:

rails generate model Person is_smart?:boolean

I haven't actually run the above statement. I assume that database fields can't have a question mark in them. Will rails deal with this appropriately? Is the best practice to simply leave question marks off of models?

Using Rails 3.2.8

Answer

cdesrosiers picture cdesrosiers · Sep 24, 2012

Rails will automatically generate the method smart? if there is a field named 'smart'.