[英]activerecord-postgis-adapter: #<ArgumentError: wrong number of arguments (3 for 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 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。
宝石文件红宝石
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'
该问题与gem activerecord-jdbc-adapter
,可以在问题#891中解决。 由于所有更改都是在分支50-stable
,因此无需更改Gemfile。 该应用程序现在在JRuby中运行:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.