Uninitialized constant Object::Foodevent (NameError)

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 = “[email protected]n.invalid”
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 `’: uninitialized constant
Object::Foodevent (NameError)

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.

Walter

Walter D. 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.

Walter

I 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.

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

Ok - I’m really stupid. Was trying to run it using ruby instead of
rails runner.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs