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:inrequire’
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:inrequire’
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:inrequire’
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:inrequire’
from primes.rb:5:in `’
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’
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.
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.
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:
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.(as you
wrote)
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.