【发布时间】:2016-06-29 04:00:11
【问题描述】:
我对 Ruby(和 Rails)还很陌生,我一直在尝试设置一个 Rails 服务器来访问 Windows 上的 PostgresQL 数据库。如果我遗漏了一些明显的东西,我会提前道歉。我正在使用最新的 Windows 版本的 Ruby 2.3.0p0,以及最新的 PostgresQL 版本,9.6 Beta 2。
我对@987654321@ 的关注有点松散,因为它是为 Ubuntu 编写的。我顺利安装了 Ruby、Rails gem 和依赖项。基本上,一切都很好,直到我去运行
rails server
command,我的命令提示符提示找不到指定的模块。我安装了 pg gem,所以我尝试了各种我发现的修复,例如将 libpq.dll 放在 ruby/bin 文件夹中,创建一个 2.3 文件夹等等。直到我删除了实际的 pg gem 本身,我的服务器才神奇地启动了。我怀疑 pg gem 覆盖了安装的 pg 版本
bundle install
命令后自动运行
gem install pg
但我实际上不确定发生了什么。有人能告诉我细节吗?
编辑,一些调试信息: 使用 vanilla pg gem,rails s 给出:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/pg.rb:14:in `require': cannot load such file -- 2.3/pg_ext
将2.2文件夹复制到2.3文件夹后,rails s给出:
C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/pg.rb:14:in `require': 126: The specified module could not be found. - C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/pg-0.18.4-x64-mingw32/lib/2.3/pg_ext.so (LoadError)
宝石文件:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.15'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
数据库.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: website_development
test:
<<: *default
database: website_test
production:
<<: *default
database: website_production
username: website
password: <%= ENV['WEBSITE_DATABASE_PASSWORD'] %>
我还没有真正将数据库链接到 Rails;我想确保 Rails 端确实首先工作。
EDIT2:
我意识到 MarsAtomic 说的是 PATH 而不是 LOADPATH,并且我意识到 ruby 出于某种原因不在我的 PATH 中。但是,将 ruby/bin 添加到我的 PATH 后,它仍然无法正常工作。我开始认为 Windows 拒绝了 .so 文件或其他东西,因为当我将 .rb 文件放在同一位置时,它发现没有问题。我还在 .dll 和 .so 上运行了文件,它报告它们都是 PE32+,而且我的 ruby 也是 64 位的,所以我认为这也不是架构问题。
【问题讨论】:
-
向我们提供您遇到的确切错误信息如何?另外,发布您的
gemfile和database.yml。了解 Postgres DB 的版本会有所帮助(它是预先存在的数据库,还是专门为 Rails 应用程序安装的?)。 -
好的,我在 OP 中添加了一些新信息。
-
你看到的很奇怪,但是,你在 Windows 上......你的 PATH 上有 libpq.dll 吗?
-
我尝试将 libpq.dll 添加到 ruby/bin 以及 PATH 中的不同位置。
标签: ruby-on-rails windows postgresql rubygems