I love using the ? for boolean fields, e.g, for ‘animals’ table “alive?” is very obvious.
Where do I define this? Do I name the db field with it when creating the table migration(don’t think so).
Or is it automatic for boolean fields or do I have a little method in the active record model class for animals that says something like def alive? if alive then true else false end ?
I love using the ? for boolean fields, e.g, for ‘animals’ table alive? is
Share
Rails automatically generates a method ending in a
?for each of the fields in a model.Some examples:
Also note that you can easily define your own
?methods: