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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Thu, 2007-01-04 at 03:15 +0100, Constantin Gavrilescu wrote:> 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 >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi, in your model def initialize#constructor @id_name="PANCHO GOMEZ, JR" end regards gaurav> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---