costi
January 4, 2007, 3:15am
1
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
costi
January 4, 2007, 3:27am
2
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
costi
January 4, 2007, 8:38am
3
hi,
in your model
def initialize#constructor
@id_name=“PANCHO GOMEZ, JR”
end
regards
gaurav