# Uninitialized Constant

**URL:** <https://www.ruby-forum.com/t/uninitialized-constant/178076>\
**Category:** Ruby\
**Created:** [October 28, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076 "2009-10-28T20:44:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/1 "2009-10-28T20:44:15Z")

</div>

I am sure that there is going to be info I leave out that you will need,  
so bear with me please. I have extremely little knowledge of ruby so I  
am sure this will be something simple (at least I hope). I am running  
ruby 1.8.6 on a FreeBSD 7.0 server. I am not the one who created the  
script so I am not sure where to start. When I run the script convert.rb  
I get:

/usr/home/admin/rails/nusers/config/…/vendor/rails/activesupport/lib/active\_support/dependencies.rb:205:in  
`const\_missing’: uninitialized constant ProvisioningAPI (NameError)  
from convert.rb:33

I have read what I need to do but I still cannot figure it out. Thank  
you in advanced for any help you can throw my way. I know there is  
probably a hundred other forum topics like this one, but like I said I  
have no idea what I am doing. Let me know if any further info is needed.  
I can post the scripts if need be.

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 8:50pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/2 "2009-10-28T20:50:38Z")

</div>

Josh Stevenson wrote:

> I am sure that there is going to be info I leave out that you will need,  
> so bear with me please. I have extremely little knowledge of ruby so I  
> am sure this will be something simple (at least I hope). I am running  
> ruby 1.8.6 on a FreeBSD 7.0 server. I am not the one who created the  
> script so I am not sure where to start. When I run the script convert.rb  
> I get:
> 
> /usr/home/admin/rails/nusers/config/…/vendor/rails/activesupport/lib/active\_support/dependencies.rb:205:in  
> `const\_missing’: uninitialized constant ProvisioningAPI (NameError)  
> from convert.rb:33
> 
> I have read what I need to do but I still cannot figure it out. Thank  
> you in advanced for any help you can throw my way. I know there is  
> probably a hundred other forum topics like this one, but like I said I  
> have no idea what I am doing. Let me know if any further info is needed.  
> I can post the scripts if need be.

Looks like you’re in a Rails application. Where does convert.rb live?  
What’s your working directory when you’re trying to run it?

Are you familiar with Rails? If not, then check out the guides at  
[http://guide.rails.info](http://guide.rails.info) , and post further questions to the Rails list  
if they’re applicable more to the Rails framework than to the Ruby  
language.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 9:07pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/3 "2009-10-28T21:07:31Z")

</div>

> Looks like you’re in a Rails application. Where does convert.rb live?  
> What’s your working directory when you’re trying to run it?
> 
> Are you familiar with Rails? If not, then check out the guides at  
> [http://guide.rails.info](http://guide.rails.info) , and post further questions to the Rails list  
> if they’re applicable more to the Rails framework than to the Ruby  
> language.
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

These are the scripts that a rails application calls on, yes. However, I  
am running the scripts as they are on the server and not by using rails  
if that makes sense. I would run it like so:  
echo admin | ruby convert.rb  
The convert.rb script lives in: /usr/home/admin/email\_conversion/  
The working directory is:  
/usr/home/admin/rails/nuser/lib/gappsprovisioning  
Further info:  
We use gmail and these scripts convert users from our database to gmail  
using the Google API.

If I am wrong and need to repost in rails section let me know and I  
will. I have been wrong once before 🙂

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 9:28pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/4 "2009-10-28T21:28:03Z")

</div>

> OK, so these scripts are not part of the Rails app, and the rails  
> directory I was seeing came from your working directory. So…the error  
> was reported at convert.rb:33. What’s on that line? It probably says  
> something about ProvisioningAPI, and that is not getting declared.
> 
> > If I am wrong and need to repost in rails section let me know and I  
> > will. I have been wrong once before 🙂
> 
> No, it looks like this isn’t a Rails issue after all…but we’ll see  
> when you post the code!
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

On that line is this:  
proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
p\_username, p\_password)

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/5 "2009-10-28T21:30:42Z")

</div>

Josh Stevenson wrote:  
[…]

> On that line is this:  
> proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
> p\_username, p\_password)

And are those classes defined anywhere?

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 9:22pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/6 "2009-10-28T21:22:23Z")

</div>

Josh Stevenson wrote:

> > Looks like you’re in a Rails application. Where does convert.rb live?  
> > What’s your working directory when you’re trying to run it?
> > 
> > Are you familiar with Rails? If not, then check out the guides at  
> > [http://guide.rails.info](http://guide.rails.info) , and post further questions to the Rails list  
> > if they’re applicable more to the Rails framework than to the Ruby  
> > language.
> > 
> > ## Best,
> > 
> > Marnen Laibow-Koser  
> > [http://www.marnen.org](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid
> 
> These are the scripts that a rails application calls on, yes. However, I  
> am running the scripts as they are on the server and not by using rails  
> if that makes sense. I would run it like so:  
> echo admin | ruby convert.rb  
> The convert.rb script lives in: /usr/home/admin/email\_conversion/  
> The working directory is:  
> /usr/home/admin/rails/nuser/lib/gappsprovisioning  
> Further info:  
> We use gmail and these scripts convert users from our database to gmail  
> using the Google API.

OK, so these scripts are not part of the Rails app, and the rails  
directory I was seeing came from your working directory. So…the error  
was reported at convert.rb:33. What’s on that line? It probably says  
something about ProvisioningAPI, and that is not getting declared.

> If I am wrong and need to repost in rails section let me know and I  
> will. I have been wrong once before 🙂

No, it looks like this isn’t a Rails issue after all…but we’ll see  
when you post the code!

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 28, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/7 "2009-10-28T21:46:00Z")

</div>

Marnen Laibow-Koser wrote:

> Josh Stevenson wrote:  
> […]
> 
> > On that line is this:  
> > proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
> > p\_username, p\_password)
> 
> And are those classes defined anywhere?
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Yes.  
Here is the entire script.  
ENV[‘RAILS\_ENV’] = ‘production’  
require ‘/usr/home/admin/rails/nusers/config/environment’  
require ‘gappsprovisioning/provisioningapi’  
include GAppsProvisioning

dual = ARGV.first == ‘–dual’

# don’t waste time with syncing password changes

CONFIG[“auth\_plugins”][“enable”] = ‘f’

# dup’d from auth\_plugins.rb

p\_domain = CONFIG[‘auth\_plugins’][‘google’][‘domain’]  
p\_username = CONFIG[‘auth\_plugins’][‘google’][‘username’]  
p\_password = CONFIG[‘auth\_plugins’][‘google’][‘password’]

proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
p\_username, p\_password)

while username = $stdin.gets  
username.chomp!  
user = User.find\_by\_uname(username)

unless user  
$stderr.puts “#{username} not found”  
next  
end

# if their password doesn’t meet requirements, gen a temp one

# and use that to create the google account if necessary.

# once the google account is created, the user can change their

# password with the new reqs and their google account will update

if user.pass.blank? || user.pass.length \< 6  
$stderr.puts “#{username} needs to change their password”  
google\_pass = Password.phonemic(8,Password::ONE\_DIGIT)  
else  
# otherwise just use their normal password  
google\_pass = user.pass  
end

# where to send mail so it lands in the user’s google account

google\_destination = “#{user.uname}@extmail.yumaed.org”

# where to send mail so it lands in both the user’s google account

# and their IMAP account

dual\_destination = [google\_destination, user.mail].join(‘,’)

# if user is already set up to have their mail sent to google,

# skip them. this lets us run this script multiple times with

# the same usernames.

next if user.mail\_destination == google\_destination

# create an account if necessary

begin  
unless proivisioner.retrieve\_user(user.uname)  
proivisioner.create\_user(user.fname, user.lname, google\_pass,  
user.uname)  
end  
rescue =\> e  
$stderr.puts “#{username} trouble creating google account: #{e}”  
next  
end

# unless the --dual argument was given, send the user’s mail

# just to google. otherwise, do dual delivery.

unless dual  
destination = google\_destination  
else  
destination = dual\_destination  
end

# set their destination to what we decided on

user.mail\_destination = destination

if user.save  
puts “#{username} updated (#{user.mail\_destination})”  
else  
$stderr.puts “#{username} problem saving:  
#{user.errors.full\_messages.join(’ / ')}”  
end  
end

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 29, 2009, 9:38am UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/8 "2009-10-29T09:38:53Z")

</div>

Josh Stevenson wrote:

> Here is the entire script.  
> ENV[‘RAILS\_ENV’] = ‘production’  
> require ‘/usr/home/admin/rails/nusers/config/environment’

Aside: another way to bootstrap the rails environment is

script/runner -e production myscript.rb

(then your script doesn’t need to contain any explicit code for this)

> require ‘gappsprovisioning/provisioningapi’  
> include GAppsProvisioning  
> …  
> proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
> p\_username, p\_password)

You need to look at the code in the file  
gappsprovisioning/provisioningapi.rb, as it doesn’t appear to define  
that class. Maybe it’s just a simple typo or a case issue, e.g. it  
should be ProvisioningApi

Another aside: because of the “include GAppsProvisioning” line above,  
you could just say

proivisioner = ProvisioningAPI.new(…)

Alternatively, you could drop the “include” line if you’re always fully  
qualifying the module name like this.

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [October 29, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/uninitialized-constant/178076/9 "2009-10-29T18:06:09Z")

</div>

Brian C. wrote:

> Josh Stevenson wrote:
> 
> > Here is the entire script.  
> > ENV[‘RAILS\_ENV’] = ‘production’  
> > require ‘/usr/home/admin/rails/nusers/config/environment’
> 
> Aside: another way to bootstrap the rails environment is
> 
> script/runner -e production myscript.rb
> 
> (then your script doesn’t need to contain any explicit code for this)
> 
> > require ‘gappsprovisioning/provisioningapi’  
> > include GAppsProvisioning  
> > …  
> > proivisioner = GAppsProvisioning::ProvisioningAPI.new(p\_domain,  
> > p\_username, p\_password)
> 
> You need to look at the code in the file  
> gappsprovisioning/provisioningapi.rb, as it doesn’t appear to define  
> that class. Maybe it’s just a simple typo or a case issue, e.g. it  
> should be ProvisioningApi
> 
> Another aside: because of the “include GAppsProvisioning” line above,  
> you could just say
> 
> proivisioner = ProvisioningAPI.new(…)
> 
> Alternatively, you could drop the “include” line if you’re always fully  
> qualifying the module name like this.

Brian,  
You were exactly right, it was a typo of sorts. Instead of it being  
ProvisioningAPI it was ProvisioningApi. I cannot believe I over looked  
that. Funny thing is, is I thought that myself and looked at it probably  
a good 20 times and never even realized that the p and i were not  
capitalized. I did remove the include from the top. Thank you all for  
your help. Changing that did reveal other errors I was able to fix. Nice  
to know there is help out there. I am reading O’Reilly’s “The Ruby  
Programming Language” book so hopefully one day I will be here to help  
someone else out. Thanks again Brian and Marnen.
