Uninitialized Constant

Discussion in 'Ruby' started by Josh Stevenson, Oct 28, 2009.

  1. 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.
    --
    Posted via http://www.ruby-forum.com/.
    Josh Stevenson, Oct 28, 2009
    #1
    1. Advertising

  2. 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 , 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

    --
    Posted via http://www.ruby-forum.com/.
    Marnen Laibow-Koser, Oct 28, 2009
    #2
    1. Advertising

  3. > 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 , 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
    >


    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 :)
    --
    Posted via http://www.ruby-forum.com/.
    Josh Stevenson, Oct 28, 2009
    #3
  4. 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 , 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
    >>

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

    --
    Posted via http://www.ruby-forum.com/.
    Marnen Laibow-Koser, Oct 28, 2009
    #4
  5. > 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
    >


    On that line is this:
    proivisioner = GAppsProvisioning::provisioningAPI.new(p_domain,
    p_username, p_password)
    --
    Posted via http://www.ruby-forum.com/.
    Josh Stevenson, Oct 28, 2009
    #5
  6. 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

    --
    Posted via http://www.ruby-forum.com/.
    Marnen Laibow-Koser, Oct 28, 2009
    #6
  7. 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
    >


    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
    --
    Posted via http://www.ruby-forum.com/.
    Josh Stevenson, Oct 28, 2009
    #7
  8. 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.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Oct 29, 2009
    #8
  9. Brian Candler 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.
    --
    Posted via http://www.ruby-forum.com/.
    Josh Stevenson, Oct 29, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=

    Uninitialized constant objects

    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=, Jun 1, 2005, in forum: C++
    Replies:
    5
    Views:
    417
    Karl Heinz Buchegger
    Jun 1, 2005
  2. Todd Gardner
    Replies:
    3
    Views:
    482
    Kaspar Schiess
    Jun 17, 2004
  3. James Hughes
    Replies:
    4
    Views:
    312
    James Hughes
    Dec 13, 2005
  4. Replies:
    2
    Views:
    129
    zycte
    Jun 15, 2006
  5. Daniel
    Replies:
    2
    Views:
    459
    Daniel
    Jun 22, 2006
Loading...

Share This Page