Sinatra 在 Cloud Foundry 上使用 Mongoid 报错

menghuanwd · 2013年04月29日 · 最后由 menghuanwd 回复于 2013年05月04日 · 3186 次阅读

在本地跑完全没有问题,在 cloud foundry 上就不行了,logs 上显示:

Mongoid::Errors::NoSessionsConfig - 
Problem:
  No sessions configuration provided.
Summary:
  Mongoid's configuration requires that you provide details about each session that can be connected to, and requires in the sessions config at least 1 default session to exist.
Resolution:
  Double check your mongoid.yml to make sure that you have a top-level sessions key with at least 1 default session configuration for it. You can regenerate a new mongoid.yml for assistance via `rails g mongoid:config`.

 Example:
 \_\_development:
 \_\_\_\_sessions:
 \_\_\_\_\_\_default:
 \_\_\_\_\_\_\_\_database: mongoid_dev
 \_\_\_\_\_\_\_\_hosts:
 \_\_\_\_\_\_\_\_\_\_- localhost:27017

:
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions/factory.rb:61:in `create_session'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions/factory.rb:43:in `default'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions.rb:109:in `default'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions.rb:378:in `__session__'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions.rb:213:in `mongo_session'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions.rb:157:in `collection'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/sessions.rb:25:in `collection'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/operations.rb:27:in `collection'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/operations/insert.rb:27:in `block in persist'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels) in prepare'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:403:in `_run__3591010883385926694__create__1044911878628526733__callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/callbacks.rb:114:in `run_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/insertion.rb:24:in `block in prepare'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:403:in `_run__3591010883385926694__save__1044911878628526733__callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/callbacks.rb:114:in `run_callbacks'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/insertion.rb:23:in `prepare'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence/operations/insert.rb:26:in `persist'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence.rb:50:in `insert'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/mongoid-3.0.9/lib/mongoid/persistence.rb:79:in `save'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/controller/user.rb:12:in `block in <top (required)>'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1415:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1415:in `block in compile!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `[]'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `block (3 levels) in route!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:960:in `route_eval'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `block (2 levels) in route!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:981:in `block in process_route'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:979:in `catch'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:979:in `process_route'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:943:in `block in route!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:942:in `each'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:942:in `route!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1053:in `block in dispatch!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `block in invoke'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `catch'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `invoke'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1050:in `dispatch!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:878:in `block in call!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `block in invoke'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `catch'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `invoke'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:878:in `call!'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:864:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:209:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:202:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:172:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1947:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1610:in `block in call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1693:in `synchronize'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1610:in `call'
    /var/vcap/data/dea/apps/novel-0-2159116fd833d9547300187427374aa6/app/rubygems/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
    /var/vcap/data/packages/dea_ruby19/7.1/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /var/vcap/data/packages/dea_ruby19/7.1/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /var/vcap/data/packages/dea_ruby19/7.1/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
180.174.37.28, 172.30.8.253 - - [29/Apr/2013 15:26:38] "GET /user/add HTTP/1.1" 500 30 0.0014
172.30.49.27 - - [29/Apr/2013:15:26:38 UTC] "GET /user/add HTTP/1.0" 500 30
- -> /user/add、




main.rb :
require 'sinatra'
require "slim"
require 'mongoid'

require_relative 'controller/user'
require_relative 'model/user'

configure :development do
  enable :logging, :dump_errors, :run, :sessions
  Mongoid.load!(File.join(File.dirname(__FILE__), "config", "mongoid.yml"))
end

mongoid.yml :
development:
  sessions:
    default:
      database: guyifeng
      hosts:
        - localhost:27017

网上查了半天,说 mongoid 的版本换成 3.0.9 就可以,但是自己试了,还是同样的错误,求高手解答

cf 好像有版本的要求,不能用最新的,不过我好久不弄这个了。

我没太注意版本,不过之前也出现过报错问题,换 VMC 好了。 实在不行嘛,把生产数据库换成 mysql

  1. 在本地能够跑起来吗? 再检查下 mongoid 的配置文件
  2. 阅读这里 ruby 1.9.3

#3 楼 @wppurking 本地能够跑得起来,我换 mysql 了

#2 楼 @xazaj 就是用 vmc 的,换 mysql 可以的

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册