Uninitialized constant ActiveRecord (NameError)

Hallo

I am running a script that starts like this:

require 'ruby-debug'
require 'circle'

first_circle=Circle.new()
@number_of_rounds=1

but i keep getting this error message:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle/models/friendship.rb:1:in
`<top (required)>': uninitialized constant ActiveRecord (NameError)
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle/circle.rb:1:in
`<top (required)>'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle.rb:7:in
`<top (required)>'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in
`rescue in require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in
`require'
  from primes.rb:5:in `<main>'

Whatshould I to do?

···

--
Posted via http://www.ruby-forum.com/.

ActiveRecord is a class that talks to databases, this gem is expecting to
be run in a context with a database connection to ActiveRecord loaded. If
you're in Rails, that means loading your Rails environment. Or if just
ActiveRecord, something like this will work:

require 'active_record'
require 'circle'

ActiveRecord::Base.establish_connection adapter: 'sqlite3', database:
':memory:'
ActiveRecord::Schema.define do
  self.verbose = false

  create_table :users do |t|
    t.string :name
    t.integer :friends_count, :default => 0, :null => false
  end

  create_table :friendships, :force => true do |t|
    t.references :user, :friend
    t.datetime :requested_at, :accepted_at, :denied_at, :blocked_at
    t.string :status
    t.timestamps
  end

  create_table :blocked_users, :force => true do |t|
    t.references :user, :blocked_user
    t.timestamps
  end

  change_table :friendships do |t|
    t.index :user_id
    t.index :friend_id
    t.index :status
  end

  change_table :blocked_users do |t|
    t.index :user_id
    t.index :blocked_user_id
  end
end

class User < ActiveRecord::Base
  has_circle
end

john = User.create! name: 'john'
mary = User.create! name: 'mary'
paul = User.create! name: 'paul'

john.befriend(mary)
john.friends?(mary) # => false
mary.accept_friend_request(john)
mary.friends?(john) # => true

But to be honest, if you don't know what ActiveRecord is, then it seems
improbable that this gem will be solving problems for you. Also, I'd be a
bit skeptical of this gem, it has a misspelling in its migration such that
it doesn't actually work unless you go fix it.

has been broken for at least 7 months without being fixed. There's <
800 downloads of the gem, which is not many (few users = fewer people
finding and fixing bugs), and it doesn't look like the author is intending
to maintain it.

···

On Sun, Mar 31, 2013 at 9:32 AM, jonathan kav <lists@ruby-forum.com> wrote:

Hallo

I am running a script that starts like this:

require 'ruby-debug'
require 'circle'

first_circle=Circle.new()
@number_of_rounds=1

but i keep getting this error message:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle/models/friendship.rb:1:in
`<top (required)>': uninitialized constant ActiveRecord (NameError)
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle/circle.rb:1:in
`<top (required)>'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in
`require'
  from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/circle-0.0.2/lib/circle.rb:7:in
`<top (required)>'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in
`require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in
`rescue in require'
  from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in
`require'
  from primes.rb:5:in `<main>'

Whatshould I to do?

--
Posted via http://www.ruby-forum.com/\.

-----------------------

Okay, I just realized what is actually happening. Took about 20 min to
write that up above, and it might help someone later googling for an issue,
so I'm going to leave it. What really happened, *I suspect*, is that you
have a gem on your system named circle, and you have a file probably in
your same directory named circle. Your load path is not properly set, so
when you `require 'circle'`, it is finding the gem and not the file you
wrote. A simple answer is to say `require File.dirname(__FILE__) +
'/circle'` instead of `require 'circle'` This isn't really the right
answer, but it will work without going into the myriad of nuances required
to figure out what the right thing is. If you want to figure out what the
right thing is, I'd need to know what Ruby version you're on, how you're
intending to use and invoke this code, and what your directory structure
looks like.

Also. If you would have said that circle.rb was a file in the same
directory, then I wouldn't have lost 20 min with the top answer. You should
provide sufficient context in the future to understand the problem.

On Mar 31, 2013, at 10:32 AM, jonathan kav <lists@ruby-forum.com>

require 'circle'

Circle is a gem for modeling activerecord relationships.
(See: https://rubygems.org/gems/circle\)

You will likely need to install activerecord to use it.

Easiest way to install it would be:

gem install activerecord

Then require it before requiring 'circle':

require 'activerecord'

Now, if you are not trying to use the circle gem (for example if
you have a file named 'circle.rb') that you are trying to require you
should require it via either of the two following methods:

require_relative 'circle'

# or

require './circle'

Hope that helps...

ok
I tried added active records as you said but i think that i am missing
the original circle.rb file so i have only half of the script.
this is an old script that was written a few years ago. i will try to
get a hold on it.
if i use the gem it doesnt work.

require 'active_record'
require 'ruby-debug'
require 'circle'

first_circle=Circle.new()
@number_of_rounds=1
primaries=Array.new
@prime_numbers=Hash.new
@prime_numbers[1]=0
#@prime_numbers

and it goes on....

i get this message

primes.rb:7:in `<main>': undefined method `new' for Circle:Module
(NoMethodError)

so you are right it is a missing script.

thank you for your help.
Jonathan

···

--
Posted via http://www.ruby-forum.com/.

You need to look in the directory of the script and see if there is a file
in there named circle.rb

The Circle gem is a red herring, it was written in mid 2012, and did not
exist several years ago.

This code isn't going to work if you don't have the other half of the
script.

-Josh

···

On Mon, Apr 1, 2013 at 4:13 AM, jonathan kav <lists@ruby-forum.com> wrote:

ok
I tried added active records as you said but i think that i am missing
the original circle.rb file so i have only half of the script.
this is an old script that was written a few years ago. i will try to
get a hold on it.
if i use the gem it doesnt work.

require 'active_record'
require 'ruby-debug'
require 'circle'

first_circle=Circle.new()
@number_of_rounds=1
primaries=Array.new
@prime_numbers=Hash.new
@prime_numbers[1]=0
#@prime_numbers

and it goes on....

i get this message

primes.rb:7:in `<main>': undefined method `new' for Circle:Module
(NoMethodError)

so you are right it is a missing script.

thank you for your help.
Jonathan

--
Posted via http://www.ruby-forum.com/\.

Agreed.

You could try to require the existing script (under ruby 1.9/2.0) with 'require_relative'.

···

On Apr 1, 2013, at 8:11 AM, Josh Cheek <josh.cheek@gmail.com> wrote:

The Circle gem is a red herring, it was written in mid 2012, and did not exist several years ago.