安装Spree ActiveRecord :: ConnectionNotEstablished错误

时间:2012-01-16 21:23:07

标签: ruby-on-rails ruby-on-rails-3 spree

我想使用rails和spree gem创建一个在线商店(http://spreecommerce.com/)。

让我的mac(os x lion)暂停rails开发一段时间,我使用本指南从头开始安装了所有内容:http://tecparatodos.com/2011/07/24/installing-ruby-on-rails-on-mac-os-x-lion/和mysql with brew。

我还关注了Spree的“入门文档”http://guides.spreecommerce.com/getting_started.html

发生的问题是在配置数据库之后使用mysql,例如做一个

rake db:create

我总是得到ActiveRecord :: ConnectionNotEstablished错误。首先,我认为它与我的mysql安装有关,但经过几个小时的检查和重新安装,我发现它实际上是因为狂欢宝石。每当我向我的Gemfile添加“gem'spree'”时,就会发生此错误。当我删除它并进行“捆绑安装”时,一切正常。我对视图项目有一些经验,但狂欢对我来说是新的。知道可能是什么问题吗?

我的database.yml:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: asiashop_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: asiashop_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: asiashop_production
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

当我做“rails c”时,我发现了这个障碍:

/Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.0.rc2/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.0.rc2/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.0.rc2/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.0.rc2/lib/active_record/model_schema.rb:224:in `columns'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.0.rc2/lib/active_record/model_schema.rb:244:in `column_names'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/ordering.rb:61:in `ordering_condition_details'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/ordering.rb:52:in `method_missing'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.40.0/lib/spree_core/find_by_param.rb:105:in `<class:Base>'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.40.0/lib/spree_core/find_by_param.rb:104:in `<top (required)>'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.0.rc2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.0.rc2/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.0.rc2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.2.0.rc2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/spree_core-0.40.0/lib/spree_core.rb:47:in `<top (required)>'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/spree-0.40.0/lib/spree.rb:1:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/spree-0.40.0/lib/spree.rb:1:in `<top (required)>'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290@global/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from /Users/mark/Documents/Workspace/Asia Testshop/asiashop/config/application.rb:7:in `<top (required)>'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:39:in `require'
    from /Users/mark/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.0.rc2/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

正如我所写,它不能成为一般的mysql连接问题,因为只要我不使用spree gem,一切正常。

2 个答案:

答案 0 :(得分:5)

您需要将Spree添加为Gemfile的宝石,如下所示:

gem 'spree', '0.70.3'

这将安装Spree的最新稳定版本。问题似乎是Bundler正在选择一个非常旧的版本(0.40.0)的Spree来运行,这是完全错误的。

答案 1 :(得分:0)

无法确定问题的根源但是在卸载所有宝石然后从头开始重新安装它们之后我就开始工作了..