← Back to Upcase

Avoiding Confusing Naming Issues in Rails


(Justin Gordon) #1

One of the most confusing causes of bugs in Rails apps is when names collide with Rails conventions.

Here’s a few places that I can think of:

###Model

  1. Don’t name any columns ending with _id unless these are foreign keys and integer values. If you use the nilify_blanks gem, which is super useful when you have tables with unique indexes that allow nulls, then columns ending with _id and _count are ignored by default.
  2. Don’t name any column type, as that’s reserved.

###Controller

  1. Don’t accidentally create any controller methods that end in _url or _path as those will conflict with route helpers.

What other names are reserved in Rails? What sort of subtle bugs have you seen related to this?