activerecord-postgis-adapter: #<ArgumentError: wrong number of arguments (3 for 4)>
activerecord-postgis-adapter: #<ArgumentError: wrong number of arguments (3 for 4)>
问题描述
我正在尝试迁移 Rails 上现有的 Ruby 应用程序(Ruby 2.3.3p222,Rails 5.0.0.1),由一位前同事开发, 至 JRuby。该应用程序 运行ning 使用上述 Ruby 版本没有任何问题。您可以在附录中找到原始 Gemfile 作为 Gemfile Ruby。
由于我是 Ruby 的新手,不确定哪里出了问题,我提供了到目前为止所做的所有更改(参见 Gemfile JRuby 在生成的 Gemfile 的附录中)将应用程序迁移到 JRuby.
1。 gem 'pg'
的替换
我用
替换了 gem 'pg', '~> 0.21.0'
gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master
按照 jruby-pg
的 Github page 指示。在 运行ning bundle install
之后,我启动了显示错误的应用程序:
LoadError: no such file to load -- active_record/connection_adapters/jdbcpostgresql_adapter
2。 gem 'activerecord-postgis-adapter'
的改编
为了消除最后一个错误,我在 gem 'activerecord-postgis-adapter'
行添加了以下内容:
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'ffi-geos'
如 activerecord-postgis-adapter
的 Github page 所建议。同样,在 bundler install
和 运行ning 之后,我得到一个错误:
Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-postgis-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
解决方法
我尝试按照 中给出的提示将 gem 'activerecord-jdbcpostgresql-adapter
行替换为
gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
:branch => "50-stable", :platform => :jruby
由于以下错误,我删除了 gem ffi-geos
,错误消失了:
Error:[rake --tasks] C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:9: warning: already initialized constant GEOS_BASE
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:90: warning: already initialized constant DimensionTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:99: warning: already initialized constant ByteOrders
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:104: warning: already initialized constant BufferCapStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:110: warning: already initialized constant BufferJoinStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:116: warning: already initialized constant ValidFlags
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:120: warning: already initialized constant RelateBoundaryNodeRules
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:128: warning: already initialized constant GeometryTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:139: warning: already initialized constant PrecisionOptions
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:786: warning: already initialized constant FFI_LAYOUT
rake aborted!
LoadError: Couldn't load the GEOS CAPI library.
... stacktrace ...
我终于可以 运行 应用程序了,但是,发送 POST 请求 returns 出现以下错误
2018-09-06 14:08:17 +0200: Rack app error handling request { POST /tripplanner/api/trip_proposals }
#<ArgumentError: wrong number of arguments (3 for 4)>
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis_adapter.rb:12:in `initialize'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/callbacks.rb:12:in `new'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/connection_methods.rb:8:in `jdbc_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/postgresql/connection_methods.rb:64:in `postgresql_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis/create_connection.rb:13:in `postgis_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection'
... stacktrace ...
我只能在 activerecord-jdbc-adapter
中找到 this 问题,但它没有说明任何解决方案。由于我没有计划如何进行,你知道错误的原因吗?非常感谢!
附录
版本信息
开发机器 运行ning 在 Windows 10 (x64) 上,使用 RubyMine 2018.2.1 作为 IDE。与 JRuby 平行,Ruby 2.3.3 仍然安装(使用 RailsInstaller)。但是,IDE 配置为使用 JRuby 作为项目的 SDK。
- Java JDK 1.8.0_172
- JRuby 9.1.17.0-p0
- PostgreSQL x64 9.5 与 PostGIS 2.3.5 r16110,GEOS 3.6.2-CAPI-1.10.2 4d2925d
- 彪马 3.6.0
Gemfiles
Gemfile Ruby
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.21.0'
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false
# gems for database handling
gem 'activerecord-postgis-adapter'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'mina'
gem 'mina-puma', github: 'untitledkingdom/mina-puma'
gem 'mina-whenever'
end
group :test do
gem 'whenever-test'
gem 'mocha'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'
Gemfile JRuby
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false
# gems for database handling
gem 'activerecord-postgis-adapter'
#gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
:branch => "50-stable", :platform => :jruby
#gem 'ffi-geos'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'mina'
gem 'mina-puma', github: 'untitledkingdom/mina-puma'
gem 'mina-whenever'
end
group :test do
gem 'whenever-test'
gem 'mocha'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'
该问题与 gem activerecord-jdbc-adapter
有关,可以在 issue #891 中解决。由于所有更改都是在分支 50-stable
上进行的,因此不需要更改 Gemfile。该应用程序现在在 JRuby 中 运行:-)
问题描述
我正在尝试迁移 Rails 上现有的 Ruby 应用程序(Ruby 2.3.3p222,Rails 5.0.0.1),由一位前同事开发, 至 JRuby。该应用程序 运行ning 使用上述 Ruby 版本没有任何问题。您可以在附录中找到原始 Gemfile 作为 Gemfile Ruby。
由于我是 Ruby 的新手,不确定哪里出了问题,我提供了到目前为止所做的所有更改(参见 Gemfile JRuby 在生成的 Gemfile 的附录中)将应用程序迁移到 JRuby.
1。 gem 'pg'
我用
替换了gem 'pg', '~> 0.21.0'
gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master
按照 jruby-pg
的 Github page 指示。在 运行ning bundle install
之后,我启动了显示错误的应用程序:
LoadError: no such file to load -- active_record/connection_adapters/jdbcpostgresql_adapter
2。 gem 'activerecord-postgis-adapter'
为了消除最后一个错误,我在 gem 'activerecord-postgis-adapter'
行添加了以下内容:
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'ffi-geos'
如 activerecord-postgis-adapter
的 Github page 所建议。同样,在 bundler install
和 运行ning 之后,我得到一个错误:
Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-postgis-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
解决方法
我尝试按照 gem 'activerecord-jdbcpostgresql-adapter
行替换为
gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
:branch => "50-stable", :platform => :jruby
由于以下错误,我删除了 gem ffi-geos
,错误消失了:
Error:[rake --tasks] C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:9: warning: already initialized constant GEOS_BASE
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:90: warning: already initialized constant DimensionTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:99: warning: already initialized constant ByteOrders
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:104: warning: already initialized constant BufferCapStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:110: warning: already initialized constant BufferJoinStyles
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:116: warning: already initialized constant ValidFlags
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:120: warning: already initialized constant RelateBoundaryNodeRules
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:128: warning: already initialized constant GeometryTypes
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:139: warning: already initialized constant PrecisionOptions
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/ffi-geos-1.2.1/lib/ffi-geos.rb:786: warning: already initialized constant FFI_LAYOUT
rake aborted!
LoadError: Couldn't load the GEOS CAPI library.
... stacktrace ...
我终于可以 运行 应用程序了,但是,发送 POST 请求 returns 出现以下错误
2018-09-06 14:08:17 +0200: Rack app error handling request { POST /tripplanner/api/trip_proposals }
#<ArgumentError: wrong number of arguments (3 for 4)>
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis_adapter.rb:12:in `initialize'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/callbacks.rb:12:in `new'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/jdbc/connection_methods.rb:8:in `jdbc_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/bundler/gems/activerecord-jdbc-adapter-9dbcf040715b/lib/arjdbc/postgresql/connection_methods.rb:64:in `postgresql_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-postgis-adapter-4.0.2/lib/active_record/connection_adapters/postgis/create_connection.rb:13:in `postgis_connection'
C:/jruby/v9.1.17.0/lib/ruby/gems/shared/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection'
... stacktrace ...
我只能在 activerecord-jdbc-adapter
中找到 this 问题,但它没有说明任何解决方案。由于我没有计划如何进行,你知道错误的原因吗?非常感谢!
附录
版本信息
开发机器 运行ning 在 Windows 10 (x64) 上,使用 RubyMine 2018.2.1 作为 IDE。与 JRuby 平行,Ruby 2.3.3 仍然安装(使用 RailsInstaller)。但是,IDE 配置为使用 JRuby 作为项目的 SDK。
- Java JDK 1.8.0_172
- JRuby 9.1.17.0-p0
- PostgreSQL x64 9.5 与 PostGIS 2.3.5 r16110,GEOS 3.6.2-CAPI-1.10.2 4d2925d
- 彪马 3.6.0
Gemfiles
Gemfile Ruby
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.21.0'
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false
# gems for database handling
gem 'activerecord-postgis-adapter'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'mina'
gem 'mina-puma', github: 'untitledkingdom/mina-puma'
gem 'mina-whenever'
end
group :test do
gem 'whenever-test'
gem 'mocha'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'
Gemfile JRuby
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '0.21.0', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master
# Use Puma as the app server
gem 'puma', '~> 3.0'
gem 'config'
gem 'whenever', :require => false
# gems for database handling
gem 'activerecord-postgis-adapter'
#gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.9'
gem 'activerecord-jdbcpostgresql-adapter', :git => "git://github.com/jruby/activerecord-jdbc-adapter.git",
:branch => "50-stable", :platform => :jruby
#gem 'ffi-geos'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'mina'
gem 'mina-puma', github: 'untitledkingdom/mina-puma'
gem 'mina-whenever'
end
group :test do
gem 'whenever-test'
gem 'mocha'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'active_model_serializers'
gem 'httparty'
gem 'polylines'
该问题与 gem activerecord-jdbc-adapter
有关,可以在 issue #891 中解决。由于所有更改都是在分支 50-stable
上进行的,因此不需要更改 Gemfile。该应用程序现在在 JRuby 中 运行:-)