NameError:启动Rails服务器时未初始化的常量ActiveRecord :: ConnectionAdapters :: MysqlAdapter

时间:2018-09-27 15:15:26

标签: mysql ruby-on-rails ruby jdbc jrubyonrails

请有人帮我解决这个问题。我正在使用MySQL数据库在Rails 3.2.13(JRuby)中构建的项目。每当我启动服务器时,都会出现以下错误。

rails s -e development -p3000
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activesupport-3.2.13/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-3.2.13/lib/active_record/associations/has_many_association.rb:52: warning: circular argument reference - reflection
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-3.2.13/lib/active_record/associations/has_many_association.rb:56: warning: circular argument reference - reflection
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-3.2.13/lib/active_record/associations/has_many_association.rb:60: warning: circular argument reference - reflection
/JRuby-9.2.0.0/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-3.2.13/lib/active_record/associations/has_many_association.rb:79: warning: circular argument reference - reflection
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. 
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. /home/jayvijay/RailsTestProject/config/environment.rb:5)
    Thu Sep 27 19:42:40 IST     /home/jayvijay/RailsTestProject/config/initializers/enhancements.rb:24: warning: constant ::Fixnum is deprecated
    /home/jayvijay/RailsTestProject/config/initializers/enhancements.rb:24: warning: constant ::Bignum is deprecated
    Exiting
    NameError: uninitialized constant ActiveRecord::ConnectionAdapters::MysqlAdapter

我知道config / initializers / enhancements.rb文件中的以下块导致流程中断。

# Patch taken from https://github.com/jruby/activerecord-jdbc-adapter/issues/229
 require 'arjdbc/mysql/adapter'
ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
  alias original_quote_string quote_string

 def quote_string(s)
    quoted_string = original_quote_string(s)
    needs_encoding?(s, quoted_string) ? quoted_string.force_encoding('UTF-8') : quoted_string
  end

  private
  def needs_encoding?(original_string, quoted_string)
    !quoted_string.frozen? && original_string.length != quoted_string.length
  end
end

因此,我随后尝试将Enhances.rb文件中的MysqlAdapter更改为Mysql2Adapter,并尝试再次启动服务器。这次服务器成功启动,但是当我在浏览器中键入localhost:3000时,产生了以下错误:

error_screenshot

请任何人提供有关解决上述问题的建议。

以下是以下版本的详细信息:-

JRuby

jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-2~14.04-b11 +jit [linux-x86_64]

铁路

Rails 3.2.13

宝石版本

2.7.6

捆绑器版本

Bundler version 1.16.5

以下是我的gemfile:-

source 'http://rubygems.org'

gem 'rails', '=3.2.13'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'execjs'
gem 'therubyrhino'
gem 'json'
gem 'bcrypt-ruby'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
gem "jruby-openssl"
gem 'net-ldap'
gem 'enum_column3'
gem "auto_form"
gem "eav_presenter"
gem "warbler"
gem "composite_primary_keys"
gem "test-unit"

#for usual admin scaffolds for AR models. See admin_controller.rb
gem "scaffolding_extensions"
gem "active_presenter"

gem "will_paginate"
gem "bitfields"

# Gems used only for assets and not required
# in production environments by default.
group :assets do
#  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'
end


group :qa do
  gem "better_errors"
end

gem 'prototype-rails'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

下面是我的database.yml文件:

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
#
# Be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
default: &default
        adapter: <%= ConfigClient.conn[:adapter] %>
        database: <%= ConfigClient.conn[:database] %>
        host: <%= ConfigClient.conn[:host] %>
        username: <%= ConfigClient.conn[:username] %>
        password: <%= ConfigClient.conn[:password] %>
        port: <%= ConfigClient.conn[:port] %>
        encoding: <%= ConfigClient.conn[:encoding] %>
        pool: 30
        timeout: 8000

development:
        <<: *default

qa:
        <<: *default

production:
        <<: *default

上面使用的ConfigClient文件:-

require 'java'
require_relative './log4j-1.2.15.jar'
require_relative './mysql-connector-java-5.1.17-bin.jar'
class ConfigClient
  def self.connection_params(db_name)
    conn = get_prop(db_name, "CONNECTION_LIST").split("|")
    default_connection_params.merge({
      :database => conn[0],
      :host => conn[1],
      :port => conn[2],
      :username => conn[3],
      :password => conn[4]
      })
  end

  def self.default_connection_params
    {:adapter => "jdbcmysql", :encoding => "utf8", :reconnect => false, :pool => 30, :timeout => 8000}
  end

  def self.conn
    connection_params("database.db.rw")
  end

以下gems已安装在我的系统中:-

gem list

*** LOCAL GEMS ***

actioncable (5.2.1)
actionmailer (5.2.1, 3.2.13)
actionpack (5.2.1, 3.2.13)
actionview (5.2.1)
active_presenter (3.2.2)
activejob (5.2.1)
activemodel (5.2.1, 3.2.13)
activerecord (5.2.1, 3.2.13)
activerecord-jdbc-adapter (50.0)
activerecord-jdbcmysql-adapter (50.0)
activeresource (3.2.13)
activestorage (5.2.1)
activesupport (5.2.1, 3.2.13)
arel (9.0.0, 3.0.3)
auto_form (0.0.2)
bcrypt (3.1.12 java)
bcrypt-ruby (3.1.5 java)
better_errors (2.5.0)
bitfields (0.8.0)
builder (3.2.3, 3.0.4)
bundler (1.16.5)
cmath (default: 1.0.0)
coderay (1.1.2)
coffee-rails (3.2.2)
coffee-script (2.4.1)
coffee-script-source (1.12.2)
composite_primary_keys (5.0.14)
concurrent-ruby (1.0.5 java)
crass (1.0.4)
csv (default: 1.0.0)
eav_presenter (0.3)
enum_column3 (0.1.4)
erubi (1.7.1)
erubis (2.7.0)
execjs (2.7.0)
fileutils (default: 1.1.0)
globalid (0.4.1)
hike (1.2.3)
httpclient (2.8.3)
i18n (1.1.0, 0.6.1)
ipaddr (default: 1.2.0)
jar-dependencies (default: 0.3.12)
jdbc-mysql (5.1.46)
journey (1.0.4)
jruby-jars (9.2.0.0)
jruby-openssl (0.10.1 java, default: 0.10.0 java)
jruby-rack (1.1.21)
jruby-readline (default: 1.2.2 java)
json (default: 2.1.0 java, 1.8.6 java)
loofah (2.2.2)
mail (2.7.0, 2.5.5)
marcel (0.3.3)
method_source (0.9.0)
mime-types (1.25.1)
mimemagic (0.3.2)
mini_mime (1.0.1)
minitest (5.11.3)
multi_json (1.13.1)
net-ldap (0.16.1)
nio4r (2.3.1 java)
nokogiri (1.8.4 java)
polyglot (0.3.5)
power_assert (1.1.3)
prototype-rails (3.2.1)
psych (default: 3.0.2 java)
rack (2.0.5, 1.4.7)
rack-cache (1.8.0)
rack-ssl (1.3.4)
rack-test (1.1.0, 0.6.3)
rails (3.2.13)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.0.4)
railties (5.2.1, 3.2.13)
rake (12.3.1)
rake-ant (default: 1.0.4)
rdoc (default: 6.0.1, 3.12.2)
rubyzip (1.2.2)
scaffolding_extensions (1.6.1)
scanf (default: 1.0.0)
sprockets (3.7.2, 2.2.3)
sprockets-rails (3.2.1)
test-unit (3.2.8)
therubyrhino (2.0.4)
therubyrhino_jar (1.7.6)
thor (0.20.0)
thread_safe (0.3.6 java)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (1.2.5, 0.3.54)
uglifier (4.1.19)
validated_arguments (0.0.1)
warbler (2.0.5)
webrick (default: 1.4.2)
websocket-driver (0.7.0 java)
websocket-extensions (0.1.3)
will_paginate (3.1.6)

Enhances.rb文件是否存在任何问题,我是否需要更改它?或安装的宝石有任何问题吗?请 有谁对此有任何想法吗?任何帮助,将不胜感激。

谢谢

0 个答案:

没有答案