Assign defaults to fields

I have this function in my model to assign defaults for create object
forms. However, it doesn’t seems right. Is there another way to do it?

DEFAULT_NAME = ‘PANCHO GOMEZ, JR’
DEFAULT_ADDRESS = ‘1234 CAMINO DEL TORRO’

def assign_defaults
self.id_name = DEFAULT_NAME if self.id_name.nil?
self.id_address = DEFAULT_ADDRESS if self.id_address.nil?
self.id_sex = DEFAULT_SEX if self.id_sex.nil?
# [ … and so on … ]
end

If this is in your database, then you could have each of your column
names use a default value, that would be overridden when you gave it a
value.

something like this would work in your migrations file:

create_table “content_nodes”, :force => true do |t|
t.column “name”, :string, :default => “”
end

Matt

hi,

in your model

def initialize#constructor
@id_name=“PANCHO GOMEZ, JR”
end

regards
gaurav