gpt4 book ai didi

ruby-on-rails-3 - Heroku 和 MongoHQ: ActionView::Template::Error (操作: #
转载 作者:行者123 更新时间:2023-12-03 01:46:37 27 4
gpt4 key购买 nike

我有一个带有 MongoID 3 的 Rails 3 应用程序已成功部署到 Heroku(使用 MongoHQ)——但随后发生了一些事情(无法确定到底是什么),并且构建开始在 Heroku 上崩溃。

所以这是我得到的错误:

TLDR: Moped::Errors::AuthenticationFailure (The operation: #<Moped::Protocol::Commands::Authenticate ... failed with error "auth fails")

使调试变得更加困难的是它在本地主机上运行得很好。现在我已经不知道这可能是什么了。

app[web.1]: >> Thin web server (v1.4.1 codename Chromeo)
app[web.1]: >> Maximum connections set to 1024
app[web.1]: >> Listening on 0.0.0.0:58731, CTRL+C to stop
heroku[web.1]: State changed from starting to up
app[web.1]:
app[web.1]:
app[web.1]: Started GET "/" for 212.86.9.90 at 2012-07-31 08:08:07 +0000
heroku[router]: GET cool-name-123.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=171ms status=200 bytes=1286
heroku[router]: GET cool-name-123.herokuapp.com/assets/application-8e7bfeeffc9291864e5b42d908c2fdda.css dyno=web.1 queue=0 wait=0ms service=11ms status=200 bytes=92524
heroku[router]: GET cool-name-123.herokuapp.com/assets/application-aa557bde70f1236cdf90c913043c4382.js dyno=web.1 queue=0 wait=0ms service=16ms status=200 bytes=122836
heroku[router]: GET cool-name-123.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=3ms status=200 bytes=0
app[web.1]:
app[web.1]:
app[web.1]: Started GET "/originals/new" for 212.86.9.90 at 2012-07-31 08:08:11 +0000
heroku[router]: GET cool-name-123.herokuapp.com/originals/new dyno=web.1 queue=0 wait=0ms service=31ms status=200 bytes=1808
app[web.1]:
app[web.1]:
app[web.1]: Started POST "/originals" for 212.86.9.90 at 2012-07-31 08:08:34 +0000
app[web.1]:
app[web.1]: Moped::Errors::AuthenticationFailure (The operation: #<Moped::Protocol::Commands::Authenticate
app[web.1]: @length=154
app[web.1]: @request_id=3
app[web.1]: @response_to=0
app[web.1]: @op_code=2004
app[web.1]: @flags=[]
app[web.1]: @full_collection_name="app123.$cmd"
app[web.1]: @limit=-1
app[web.1]: @skip=0
app[web.1]: @selector={:authenticate=>1, :user=>"heroku", :nonce=>"xyz", :key=>"xyz"}
heroku[router]: POST cool-name-123.herokuapp.com/originals dyno=web.1 queue=0 wait=0ms service=1486ms status=500 bytes=643
app[web.1]: @fields=nil>
app[web.1]: failed with error "auth fails"):
app[web.1]: app/controllers/originals_controller.rb:19:in `block in create'
app[web.1]: app/controllers/originals_controller.rb:18:in `create'
app[web.1]:
app[web.1]:
heroku[router]: GET cool-name-123.herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=3ms status=304 bytes=0
app[web.1]:
app[web.1]:
app[web.1]: Started GET "/" for 212.86.9.90 at 2012-07-31 08:09:40 +0000
heroku[router]: GET cool-name-123.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=11ms status=304 bytes=0

我最近在 Heroku 上遇到了困难,因此我认为我应该对数据库驱动程序和服务的选择进行正确的设置(在 Gemfile 中使用新的 yml 方案 + Ruby 1.9.3)。

当我运行heroku config --app app_name时我明白

DATABASE_URL        => postgres://rhalppyjrb:xyz@ec2-xyz.compute-1.amazonaws.com/rhalppyjrb
GEM_PATH => vendor/bundle/ruby/1.9.1
LANG => en_US.UTF-8
MONGOHQ_URL => mongodb://heroku:xyz@flame.mongohq.com:27054/app123
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV => production
RAILS_ENV => production
SHARED_DATABASE_URL => postgres://rhalppyjrb:xyz@ec2-123.compute-1.amazonaws.com/rhalppyjrb

我的 mongoid.yml 看起来像这样:

production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
options:
consistency: :strong
skip_version_check: true
safe: true

Gemfile 是这样的:

source 'https://rubygems.org'

gem 'bundler', '1.2.0.rc'

ruby '1.9.3'

gem 'rails', '3.2.6'
gem 'thin'
gem 'rmagick', :require => 'RMagick'
gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0", :require => 'carrierwave/mongoid'

group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem "therubyracer", :platform => :ruby
end

gem 'jquery-rails'
gem "haml", ">= 3.1.6"
gem "mongoid", ">= 3.0.3"
gem "devise", ">= 2.1.2"
gem "devise_invitable", ">= 1.0.2"
gem "cancan", ">= 1.6.8"
gem "rolify", ">= 3.1.0"
gem "bootstrap-sass", ">= 2.0.4.0"
gem "simple_form"

group :development do
gem "guard", ">= 0.6.2"
gem 'rb-fsevent'
gem 'growl'
gem "haml-rails", ">= 0.3.4"
gem "guard-bundler", ">= 0.1.3"
gem "guard-rails", ">= 0.0.3"
gem "guard-livereload", ">= 0.3.0"
gem "guard-rspec", ">= 0.4.3"
end

group :test do
gem "database_cleaner", ">= 0.8.0"
gem "mongoid-rspec", "1.4.6"
gem "email_spec", ">= 1.2.1"
end

group :development, :test do
gem "factory_girl_rails", ">= 3.5.0"
gem "rspec-rails", ">= 2.11.0"
end

最佳答案

问题是您的身份验证凭据不再正确。具体来说,您尝试验证的用户已不存在。

原因是,当您执行rake db:reseed时,所有数据都会被删除,包括数据库级别用户。

示例:

  ➜  skadi git:(master) ✗ mongo         
MongoDB shell version: 2.0.7
connecting to: test
> use skadi_development
switched to db skadi_development
> db.system.users.find()
> db.addUser("joe", "passwordForJoe")
{ "n" : 0, "connectionId" : 191, "err" : null, "ok" : 1 }
{
"user" : "joe",
"readOnly" : false,
"pwd" : "dac588613249fe92703afb262ec53b82",
"_id" : ObjectId("5030d5181cefbd2b04a99e30")
}
> db.system.users.find()
{ "_id" : ObjectId("5030d5181cefbd2b04a99e30"), "user" : "joe", "readOnly" : false, "pwd" : "dac588613249fe92703afb262ec53b82" }
> exit
bye

➜ skadi git:(master) ✗ rake db:reseed

➜ skadi git:(master) ✗ mongo
MongoDB shell version: 2.0.7
connecting to: test
> use skadi_development
switched to db skadi_development
> db.system.users.find()
=> Nothing

因此,当您尝试连接到数据库时,您的凭据不再有效。

您可以在 MongoHQ 管理面板中检查这一点。您可以通过转到 Heroku、选择您的应用程序、单击资源并单击 MongoHQ 来找到它。然后单击“数据库用户”选项卡。

rake db:reseed 曾经按您的预期工作,但它随着 mongoid 的新版本而改变。为了删除除 system.* 之外的所有集合,您可以使用 rake db:purge

您可能需要使用 master 分支,因为该 rake 任务在稳定版本中尚不可用。或者只是在代码中使用 Mongoid.purge!,它可以稳定运行。

详细信息:https://github.com/mongoid/mongoid/issues/2275

关于ruby-on-rails-3 - Heroku 和 MongoHQ: ActionView::Template::Error (操作: #<Moped::Protocol::Commands::Authenticate 失败,错误 "auth fails"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11735921/

27 4 0

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