activerecord-postgis-adapter: #<ArgumentError: 错误的参数数(3 表示 4)>



>问题描述

我正在尝试将前同事开发的现有Ruby on Rails应用程序(Ruby 2.3.3p222,Rails 5.0.0.1(迁移到JRuby。该应用程序使用上述 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页面的说明。运行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页面所建议的那样。同样,在bundler install并运行后,我收到一个错误:

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 请求会返回以下错误

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中找到这个问题,但它没有说明任何解决方案。由于我没有计划如何进行,您对错误的原因有任何想法吗?多谢!


附录

版本信息

开发计算机在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 with PostGIS 2.3.5 r16110, GEOS 3.6.2-CAPI-1.10.2 4d2925d
  • 彪马 3.6.0

宝石文件

宝石文件红宝石

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'

宝石档案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'

该问题与宝石activerecord-jdbc-adapter有关,可以在问题 #891 中解决。由于所有更改都是在分支50-stable上进行的,因此不需要更改 Gemfile。该应用程序现在在JRuby中运行:-(

相关内容

  • 没有找到相关文章

最新更新