It looks like Rails doesn't get properly initialized.
Can you post the script, and explain how you run / start it?
Which version of Rails do you use?
If you have a rails application and you want to run a task as a script, there are two ways to do it:
1) via script runner
2) via rake
If you use rake, you have to tell it to initialize your Rails application properly.
The rake tasks need to be under ./lib/tasks
Check out these Posts, which explain how to do it:
I have a Rails task: should I use script/runner or rake?
script/runner in rails 3
http://guides.rubyonrails.org/active_record_querying.html