我想用rails和spread gem创建一个在线商店(http://spreecommerce.com/)。
让rails开发在我的mac(os x lion)上休息一段时间,我使用此指南从头开始安装了所有内容:http://tecparatodos.com/2011/07/24/installing-ruby-on-rails-on-mac-os-x-lion/和带有brew的mysql。
我还学习了Spree的"入门文档"http://guides.spreecommerce.com/getting_started.html
发生的问题是使用mysql,在配置数据库后,例如进行
rake db:create
我总是得到ActiveRecord::ConnectionNotEstablished错误。起初我认为这与我的mysql安装有关,但经过数小时的检查和重新安装,我发现这实际上是因为疯狂的宝石。每当我在我的Gemfile中添加"宝石狂欢"时,就会出现这个错误。当我删除它并进行"捆绑安装"时,一切都很好。我在景观项目上有一些经验,但狂欢对我来说是新鲜事。你知道问题出在哪里吗?
我的数据库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"时的stracktrace:
/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连接问题,因为只要我不使用spread gem,一切都很好。
您需要将Spree作为宝石添加到Gemfile
中,如下所示:
gem 'spree', '0.70.3'
这将安装最新的稳定版本的Spree。问题似乎是Bundler选择了一个非常旧的Spree版本(0.40.0)来运行,这完全是错误的。
无法真正确定问题的根源,但在卸载所有gem并从头开始重新安装后,我使其正常工作。。