views:

20

answers:

1

You can initialize a db attribute to a default value in the following two ways -

  1. Configure your db to assign a default value to that attribute
  2. Use Ruby's initialize method to assign it a value during Object creation (using something like ActiveRecord to talk to your db)

Is there a reason to prefer one of the above methods over another?

Performance? Maintenance of your code (in the sense that all business logic resides in your Model)?

+1  A: 

If we build the defaults into the database then any application which writes to the database can avail itself of them. Otherwise we have to duplicate the logic in each application.

Now, whether that swings it rather depends on how likely it is that multiple applications will use the database. The lessons of history are that databases tend to outlive their front-ends. But this doesn't apply universally.

APC