gpt4 book ai didi

ruby-on-rails - rails 环境 mongoid 连接问题

转载 作者:可可西里 更新时间:2023-11-01 09:07:07 26 4
gpt4 key购买 nike

我有 Rails 应用程序 3.2.17,部署在 staging 环境中,unicorn 4.6.3 由 bluepill 0.0.66 使用 mongid 3.1.5 监控

当我为暂存环境部署时,所有工作都发现包括 active_record,但 mongoid 查询除外,结果出现以下错误:

Error during failsafe response: 
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash.

部署站点中的mongoid.yml文件

staging:
sessions:
default:
database: mydb
username: user
password: password
hosts:
- localhost:27017
options:
options:

部署站中的myapp.pill文件

Bluepill.application('myapp', log_file: '/var/log/bluepill/myapp.log') do |app|
app.process('myapp-app') do |process|
process.pid_file = '/home/user/myapp/current/tmp/pids/unicorn.pid'
process.working_dir = '/home/user/myapp/current'
process.start_command = '/home/user/.gem/ruby/1.9.1/bin/bundle exec unicorn -c config/unicorn.rb -D -E staging'
process.stop_command = 'kill -QUIT {{PID}}'
process.restart_command = 'kill -USR2 {{PID}}'
process.uid = 'user'
process.gid = 'user'
process.start_grace_time 30.seconds
process.stop_grace_time 30.seconds
process.restart_grace_time 60.seconds
process.monitor_children do |child_process|
child_process.stop_command 'kill -QUIT {{PID}}'
child_process.checks(:mem_usage,
:every => 30.seconds,
:below => 1024.megabytes,
:times => [3,4]
)
child_process.checks(:cpu_usage,
:every => 30.seconds,
:below => 90,
:times => [3,4]
)
end
end
end

我怀疑 mongoid 没有收到 RAILS_ENV,但我不确定,我检查了 mongoid.yml 中的缩进。应该还有别的原因我没查出来。

最佳答案

在/config/application.rb 中输入

require 'mongoid'

Mongoid.load!(File.expand_path('mongoid.yml', './config'))

它可能是通过初始化器来完成的。

关于ruby-on-rails - rails 环境 mongoid 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24369990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com