Rails model without corresponding database tables

Lately, I’ve been fortunate enough to contribute to Dot429. It is, among other things, a great place for the LGBT community and their supporters to connect, discuss business and mentor each other.

One of the mini-projects, a contest, required us to ask for a telephone number, but in three separate fields: (area-code), (first three digits), (last four digits). Once the fields were accepted and validated, they were to be concatenated and stored in the database.

Rails makes this very easy: just add the accessors for non-database fields and validate them as we normally would through the built in validators:

When the save() function is called in the controller, the model should validate just fine, even if the particular fields do not correspond to columns in the database.

Now, what if we want to make use of validators for a model that has no table in the database?
Rails throws its arms in the air if you do the above but for a model that has no corresponding database table. The solution is simple: create a dummy table. This, in my opinion, is the simplest solution to the problem because it makes Rails happy. We can even create one dummy talble and associate it to any model that does not have a corresponding database table. Like so: