--- Z@m ---
2009-Mar-05 13:38 UTC
how to give default value to fields in a model while creating model_name.new()
am a newbie to rails , I created a model named Employee and in migration i added the following class CreateEmployee < ActiveRecord::Migration def self.up create_table :employees do |t| t.string :name, :limit => 40, :null => false,:default => "" t.text :address, :limit => 200,:default => "" t.text :location_name, :default => "",:limit => 200 t.text :city, :default => "",:limit => 200 t.text :state, :default => "",:limit => 200 t.integer :zipcode, :limit => 6 t.timestamps end end def self.down drop_table :employees end end i gave default to almost all the fields esp which are string or text but when i took the console and created a new instance of the class say Employee.new i find the default argument is not working>> Employee.new=> #<Employee id: nil, name: "", address: nil, location_name: nil, city: nil, state: nil, zipcode: nil, created_at: nil, updated_at: nil>>>only the name is given a default value of "" rest is still nill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Starr Horne
2009-Mar-05 13:57 UTC
Re: how to give default value to fields in a model while creating model_name.new()
On Thu, 5 Mar 2009 05:38:24 -0800 (PST) "--- Z@m ---" <krishnaprasadvarma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > am a newbie to rails , I created a model named Employee > > and in migration i added the following > > class CreateEmployee < ActiveRecord::Migration > def self.up > create_table :employees do |t| > > t.string :name, :limit => 40, :null => false,:default => "" > t.text :address, :limit => 200,:default => "" > t.text :location_name, :default => "",:limit => 200 > t.text :city, :default => "",:limit => 200 > t.text :state, :default => "",:limit => 200 > t.integer :zipcode, :limit => 6Are you using mysql? If so, it doesn''t support default values for "text" columns. SH -- Starr Horne My blog: http://starrhorne.com Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
--- Z@m ---
2009-Mar-06 05:18 UTC
Re: how to give default value to fields in a model while creating model_name.new()
yea am using mysql sad ! ! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---