activerecord-postgis-adapter:#<argumenterror:错误=“” number =“” of =“” arguments =“”(3 =“” for =“” 4)=“”>

时间:2018-09-06 12:41:09

标签: ruby-on-rails ruby rubygems rails-activerecord activerecord-jdbc

问题描述

我试图将由前同事开发的现有Ruby on Rails应用程序(Ruby 2.3.3p222,Rails 5.0.0.1)迁移到JRuby。使用上述Ruby版本,该应用程序运行无任何问题。您可以在附录中找到作为 Gemfile Ruby 的原始Gemfile。

由于我是Ruby的新手,并且不确定出什么问题,因此我提供了到目前为止所做的所有更改(有关生成的Gemfile,请参阅附录中的 Gemfile JRuby ),以将应用迁移到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的{​​{3}}的指示进行操作。运行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的{​​{3}}建议的

。同样,在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

解决方法

我尝试遵循Github page中给出的提示,并用{p1

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

最后我可以运行该应用程序,但是,发送POST请求将返回以下错误

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 ...

我只能在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 ... 中找到Github page问题,但没有说明任何解决方案。由于我没有计划如何进行操作,因此您对错误原因有任何想法吗?非常感谢!


附录

版本信息

开发机器正在Windows 10(x64)上运行,并使用RubyMine 2018.2.1作为IDE。与JRuby并行,仍安装了Ruby 2.3.3(使用this post)。但是,IDE已配置为使用JRuby作为项目的SDK。

  • Java JDK 1.8.0_172
  • JRuby 9.1.17.0-p0
  • 具有PostGIS 2.3.5 r16110,GEOS 3.6.2-CAPI-1.10.2 4d2925d的PostgreSQL x64 9.5
  • 彪马3.6.0

宝石文件

Gemfile Ruby

activerecord-jdbc-adapter

宝石文件JRuby

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'

1 个答案:

答案 0 :(得分:0)

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