uninitialized constant Neo4j::Session (NameError) - ruby

Reading the instructions contained in the address https://neo4j.com/developer/ruby/ I built the following code:
require 'neo4j'
session = Neo4j::Session.open(
:server_db,
"http://neo4j:password#localhost:7687"
)
I have this error:
uninitialized constant Neo4j::Session (NameError).
I don't understand if it is necessary to instantiate Neo4j or if it is necessary to redefine Session. Do you have any suggestions?

Related

org.jruby.exceptions.RaiseException: (NameError) uninitialized constant

I'm getting the following error from a JRuby wrapping of the ActiveMerchant library:
org.jruby.exceptions.RaiseException: (NameError) uninitialized constant ActiveMerchant::Billing::SecurePayAuGateway
at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java:3345)
at org.jruby.RubyModule.const_get(org/jruby/RubyModule.java:3290)
at RUBY.createGateway(classpath:/scripts/main.rb:79)
The code initiating it is:
gateway = ActiveMerchant::Billing::const_get(name).new(options)
I think this is happening because there is some dynamic loading of the gateways happening in gateways.rb:
module ActiveMerchant
module Billing
load_path = Pathname.new(__FILE__ + '/../../..')
Dir[File.dirname(__FILE__) + '/gateways/**/*.rb'].each do |filename|
gateway_name = File.basename(filename, '.rb')
gateway_classname = "#{gateway_name}_gateway".camelize
gateway_filename = Pathname.new(filename).relative_path_from(load_path).sub_ext('')
autoload(gateway_classname, gateway_filename)
end
end
end
This works during unit tests because the Ruby files are real files in my target directory. However in the final application, the Ruby files are contained within a Jar which is in a Jar.
Anyone know why this is happening and how to get it to work?
Which gateway are you trying to teach? From Active Merchant's github there is no
ActiveMerchant::Billing::SecurePayAuGateway
But there is a
ActiveMerchant::Billing::SecurePayGateway
And a
ActiveMerchant::Billing::SecurePayTechGateway
To test, instead of
gateway = ActiveMerchant::Billing::const_get(name).new(options)
Try
gateway = ActiveMerchant::Billing::SecurePayGateway
If this works, you know the problem is your gateway = method and you can fix this accordingly

NameError: uninitialized constant ActiveModel::Serializers::Xml when declaring a mongomapper document model

This is the first time I use ruby mongodb ORM , and when I follow the tutorial on the website try to make a Document model :
ruby require 'mongo_mapper'
include MongoMapper::Document
key :title, String
key :content, String
key :published_at, Time
timestamps!
end
my command line issue the error
NameError: uninitialized constant ActiveModel::Serializers::Xml
from /Users/RobertRino/.rvm/gems/ruby-2.2.3/gems/mongo_mapper-0.14.0/lib/mongo_mapper/plugins/active_model.rb:9:in'`
and the app crashed.
I searched for solution but seems no one have encountered this problem, could anyone tell me how to solve this error ?
By the way I also try the command above in pry gem.
require 'mongo_mapper'
>>True
MongoMapper.constants
>>[:Error,
:DocumentNotFound,
:InvalidScheme,
:DocumentNotValid,
:AccessibleOrProtected,
:InvalidKey,
:NotSupported,
:Document,
...]
MongoMapper::Document
>> NameError ... (the same error)
Has been moved to external gem, please try to add this to your Gemfile:
gem 'activemodel-serializers-xml'
gem 'active_model_serializers'

undefined method `[]' for nil:NilClass (NoMethodError)

i am using sequel gem and postgresql database
i have a file hello.rb with code
require "rubygems"
require './post'
require "sequel"
# connect to an in-memory database
DB = Sequel.connect('postgres://ritesh:newpassword#localhost')
post = Post['ruby1', 'hello world1']
post[1]
and i created a table post and
a model with code
require 'sequel'
DB = Sequel.connect('postgres://ritesh:newpassword#localhost')
class Post < Sequel::Model
set_primary_key [:category, :title]
end
when i run command ruby hello.rb .i am getting the following error
hello.rb:10: undefined method `[]' for nil:NilClass (NoMethodError)
first thing i want to know for creating we should create a table with that name and then create a model??
second thing if first assumption is true then why i am getting this error??
To construct a new object in ruby you should call new. I am not sure what is post but it seems the correct syntax should be:
post = Post.new('ruby1', 'hello world1')
Otherwise post will remain null after this line.

undefined method `create_db' for #<Mysql:0x000000018f2590> (NoMethodError)

#!/usr/local/bin/ruby
require 'mysql'
db=Mysql.new '127.0.0.1','root','123456'
db.create_db 'testdb'
error message:
test.rb:5:in `<main>': undefined method `create_db' for #<Mysql:0x000000015d0ab0> (NoMethodError)
What's wrong?
Though it is still in the API, create_db cannot be used since mysql4.1.
This function is deprecated. It is preferable to use mysql_query() to
issue an SQL CREATE DATABASE statement instead.
Therefore you need to use query as
require 'mysql'
db = Mysql::new('127.0.0.1','root','123456')
db.query("create database testdb;");
db.close

SWIG: Ruby overloading problems

I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig.
I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous function names are always mapped to this library.
The reason is that 'require' does only load stuff that is not already loaded, whereas 'load' reloads no matter what. However, 'load' seems not to be applicable to .so files, only to ruby source files. Any help?
Thank you
require looks in $" array to determine if a module should be reloaded. You could try deleting it and requiring. Not sure if this will work for your use case, though, as it seems that the namespace still can be left polluted.
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> require 'mysql'
=> false
irb(main):003:0> $".delete('mysql.so')
=> "mysql.so"
irb(main):004:0> require 'mysql'
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlRes
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlField
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant MysqlError
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant VERSION
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_CONNECT_TIMEOUT
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_COMPRESS
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux/mysql.so: warning: already initialized constant OPT_NAMED_PIPE
<snip>
=> true

Resources