我正在开发一个Rails应用程序。使用的数据库是OrientDB。我正在使用active-orient
gem。一切都运行良好,直到我更新我的Bundler版本。之后,我无法使用rails c
打开Rails控制台。以下是错误堆栈
$ rails c
Railtie included!!
I, [2017-09-21T19:48:05.335384 #25012] INFO -- : Orientdb4r 0.5.1, running on Ruby 2.4.0 (2016-12-24) [x86_64-linux]
WARNING: Use strings for Figaro configuration. 5432 was converted to "5432".
WARNING: Use strings for Figaro configuration. 2480 was converted to "2480".
WARNING: Use strings for Figaro configuration. 100000000 was converted to "100000000".
/home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): http://localhost:2480/connect/ENV['orientdb_database'] (URI::InvalidURIError)
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/uri/rfc3986_parser.rb:73:in `parse'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/uri/common.rb:231:in `parse'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/rest-client-1.8.0/lib/restclient/request.rb:276:in `parse_url'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/rest-client-1.8.0/lib/restclient/request.rb:280:in `parse_url_with_auth'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/rest-client-1.8.0/lib/restclient/request.rb:175:in `execute'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/rest-client-1.8.0/lib/restclient/request.rb:41:in `execute'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/rest-client-1.8.0/lib/restclient/resource.rb:51:in `get'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/bundler/gems/active-orient-4f90f0276d4c/lib/rest/rest.rb:105:in `connect'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/bundler/gems/active-orient-4f90f0276d4c/lib/rest/rest.rb:83:in `initialize'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/bundler/gems/active-orient-4f90f0276d4c/lib/railtie.rb:42:in `new'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/bundler/gems/active-orient-4f90f0276d4c/lib/railtie.rb:42:in `block in <class:Railtie>'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/railties-5.0.6/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/railties-5.0.6/lib/rails/initializable.rb:30:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/railties-5.0.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `call'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/railties-5.0.6/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/railties-5.0.6/lib/rails/application.rb:352:in `initialize!'
from /home/ubuntu/my-project/config/environment.rb:5:in `<top (required)>'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `block in require'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in `require'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application.rb:102:in `preload'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
我的config/application.yml
文件:
development:
orientdb_port: 2480
orientdb_server: <some-ip>
orientdb_root_username: <some-username>
orientdb_root_password: <some-password>
orientdb_database: <some-db-name>
我用来提供OrientDB gem详细信息的config/connect.yml
文件:
:orientdb:
:server: ENV["orientdb_server"]
:port: ENV["orientdb_port"]
:logger: stdout
:database:
:development: ENV["orientdb_database"]
:production: ENV["orientdb_database"]
:test: ENV['orientdb_database']
:staging: ENV['orientdb_database']
:admin:
:user: ENV['orientdb_root_username']
:pass: ENV['orientdb_root_password']
我认为此文件未正确加载。这可能是什么问题? 我甚至降级了捆绑版本,但仍然无效。
答案 0 :(得分:0)
development:
orientdb_port: '2480'
orientdb_server: 'some-ip'
orientdb_root_username: 'some-username'
orientdb_root_password: 'some-password'
orientdb_database: 'some-db-name'
在终端运行中:figaro install
这将包括(.gitignore)
答案 1 :(得分:0)
您的config/connect.yml
文件应如下所示:
orientdb:
server: <%= ENV['orientdb_server'] %>
port: <%= ENV['orientdb_port'] %>
logger: stdout
database:
development: <%= ENV['orientdb_database'] %>
production: <%= ENV['orientdb_database'] %>
test: <%= ENV['orientdb_database'] %>
staging: <%= ENV['orientdb_database'] %>
admin:
user: <%= ENV['orientdb_root_username'] %>
pass: <%= ENV['orientdb_root_password'] %>
YML 不是 Ruby,因此您必须使用Ruby语句的erb标记来访问环境变量。这同样适用于config/application.yml
。
如果仔细查看错误消息,您会看到以下行几乎说明了失败的原因:
/home/ubuntu/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): http://localhost:2480/connect/ENV['orientdb_database'] (URI::InvalidURIError)
具体来说,http://localhost:2480/connect/ENV['orientdb_database'] (URI::InvalidURIError)
表示您将字符串ENV['orientdb_database']
传递给连接而不是实际的环境变量。
答案 2 :(得分:0)
假设您使用的是最新版本的active-orient(来自github),请查看lib目录中的railties.rb文件。
connect_file = Rails.root.join('config', 'connect.yml')
databaseyml = YAML.load_file( connect_file )[:orientdb][:database]
因此:yaml标记必须是:orientdb:和:database:
您可以轻松调试输入,将控制输出添加到railtie文件中 例如
puts "DATABASEYML :#{databaseyml.inspect}"
如果使用Environment-variable设置数据库,只需将其分配给ActiveOrient.database
ActiveOrient.database = ENV['orientdb_database']
任何事都应该有用。