ruby-on-railsruby-on-rails-3coding-stylenaming-conventions

Ruby on rails convention for naming date/time fields


I want to make a scaffold like this:

rails generate scaffold Job started_at:datetime completed_at:datetime price:decimal paid_at:datetime estimated_completion_at:datetime comment:text

I've added "_at" to the datetime fields because that seemed to be the convention as rails timestamp fields are either "_at" for datetime or "_on" for date. But is this actually a convention? Is it OK if I just have "paid" instead of "paid_at" and "completed" instead of "completed_at"?

I really want to get this right from the start. I've been programming in c# for years but I'm new to ruby on rails. I like all the conventions and I want to make sure I'm doing this the proper 'rails way'.


Solution

  • I don't know of any specific rails convention, and it doesn't really matter since there's nothing in rails that keys off of datetime fields. The convention I've always gone with is suffix datetime columns with _at and date columns with _on. It always seemed more natural to say on a day and at a time.