如何将jruby / activerecord-jdbcmssql-adapter用于全新的Rails应用程序(最好是Rails 5+)

时间:2018-07-17 07:14:16

标签: jdbc jrubyonrails mssql-jdbc

我正在尝试使用jruby创建一个新的Rails应用,下面是我的gemfile。

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.7'
# Use jdbcmssql as the database for Active Record
gem 'activerecord-jdbcmssql-adapter'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyrhino'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development


# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development do
  gem 'listen'
end

我运行bundle install并成功安装。
问题是当我运行rails srails c时,它给我错误:

Bundler::GemRequireError: There was an error while trying to load the gem 'activerecord-jdbcmssql-adapter'.
Gem Load Error is: uninitialized constant ActiveRecord::ConnectionAdapters::Column::Format
Backtrace for gem load error is:
/Users/jep/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.22/lib/arjdbc/jdbc/type_cast.rb:13:in `<module:TypeCast>'
/Users/jep/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.22/lib/arjdbc/jdbc/type_cast.rb:7:in `<module:Jdbc>'
/Users/jep/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.22/lib/arjdbc/jdbc/type_cast.rb:4:in `<module:ConnectionAdapters>'
/Users/jep/.rbenv/versions/jruby-9.2.0.0/lib/ruby/gems/shared/gems/activerecord-jdbc-adapter-1.3.22/lib/arjdbc/jdbc/type_cast.rb:3:in `<main>'
...

我的问题是,此gem支持rails 5(任何版本)吗?
因为我的要求是使用jruby和mssql。看来这是唯一可用的宝石。

如果它不能支撑滑轨5,可以支撑滑轨4吗?什么rails 4版本?

1 个答案:

答案 0 :(得分:1)

我已经在4.2.10中尝试了它,并且可以为gem设置版本。

在此问题中查看我的答案,该答案具有我的设置:
Gem Load Error is: undefined method `type_cast_from_database' for class `ArJdbc::MSSQL::UUIDType'

关于rails 5,我不确定。