# Uninitialized constant ActiveRecord (NameError)

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant-activerecord-nameerror/187726>\
**Category:** Ruby\
**Created:** [April 28, 2010, 11:04am UTC](https://www.ruby-forum.com/t/uninitialized-constant-activerecord-nameerror/187726 "2010-04-28T11:04:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 11:04am UTC](https://www.ruby-forum.com/t/uninitialized-constant-activerecord-nameerror/187726/1 "2010-04-28T11:04:49Z")

</div>

Hi All,

I am running a script from console line with command as ruby  
script/abc.rb. But i am getting error “uninitialized constant  
ActiveRecord (NameError)”. Why so … ?  
My first line of the script is class-

CronJobs \< ActiveRecord::Base  
…  
…  
end

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 11:29am UTC](https://www.ruby-forum.com/t/uninitialized-constant-activerecord-nameerror/187726/2 "2010-04-28T11:29:26Z")

</div>

On Wed, Apr 28, 2010 at 11:04 AM, Hemant B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am running a script from console line with command as ruby  
> script/abc.rb. But i am getting error “uninitialized constant  
> ActiveRecord (NameError)”. Why so … ?  
> My first line of the script is class-
> 
> CronJobs \< ActiveRecord::Base  
> …  
> …  
> end

If that script belongs to a Rails application run it with script/runner  
instead:

```
script/runner script/abc.rb

```

On the other hand, if you are using Active Record stand-alone then you  
need to load it as any other library.

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [April 28, 2010, 11:59am UTC](https://www.ruby-forum.com/t/uninitialized-constant-activerecord-nameerror/187726/3 "2010-04-28T11:59:47Z")

</div>

Xavier N. wrote:

> If that script belongs to a Rails application run it with script/runner  
> instead:
> 
> ```
> script/runner script/abc.rb
> 
> ```
> 
> On the other hand, if you are using Active Record stand-alone then you  
> need to load it as any other library.

O O… yeah yeah. This is the correct way. Thanks for your time… 🙂
