I have a model named Foodevent which I am trying to use to insert objects into my database. This is my code ---------------------------- require ''rubygems'' e_from = "john.doe-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org" e_subject = "first post" e_date = "2011-12-03" e_time = "18:00" e_body = "testing testing" fevent = Foodevent.new( :from => e_from, :subject => e_subject, :date => e_date, :time => e_time, :body => e_body ) fevent.save ---------------------------- However I am getting this error repeatedly - why is that? db/scripts/vbtest.rb:17:in `<main>'': uninitialized constant Object::Foodevent (NameError) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Nov-18 23:16 UTC
Re: uninitialized constant Object::Foodevent (NameError)
On Nov 18, 2011, at 6:13 PM, Eugene Moy wrote:> I have a model named Foodevent which I am trying to use to insert > objects into my database. This is my code > ---------------------------- > require ''rubygems'' > > e_from = "john.doe-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org" > e_subject = "first post" > e_date = "2011-12-03" > e_time = "18:00" > e_body = "testing testing" > > fevent = Foodevent.new(At this point, have you already declared or required the Foodevent class? From the sounds of that error, I think maybe it isn''t there yet. Walter> :from => e_from, > :subject => e_subject, > :date => e_date, > :time => e_time, > :body => e_body > ) > fevent.save > ---------------------------- > However I am getting this error repeatedly - why is that? > > db/scripts/vbtest.rb:17:in `<main>'': uninitialized constant > Object::Foodevent (NameError) > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think I did? I ran rails generate scaffold Foodevent from:string subject:string date:string time:string body:text and rake db:migrate before running the script. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis wrote in post #1032619:> On Nov 18, 2011, at 6:13 PM, Eugene Moy wrote: > >> >> fevent = Foodevent.new( > > At this point, have you already declared or required the Foodevent > class? From the sounds of that error, I think maybe it isn''t there yet. > > WalterI think I did? I created a new project then ran rails generate scaffold Foodevent from:string subject:string date:string time:string body:text and rake db:migrate before running the script. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok - I''m really stupid. Was trying to run it using `ruby` instead of `rails runner`. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2011-Nov-19 14:46 UTC
Re: Re: uninitialized constant Object::Foodevent (NameError)
Not at all. Rails does so much magic most of the time, you don''t realize you don''t have it until it doesn''t happen. Walter On Nov 18, 2011, at 8:04 PM, Eugene Moy wrote:> Ok - I''m really stupid. Was trying to run it using `ruby` instead of > `rails runner`. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.