Rails Rails 连接多个数据库的配置问题

paranoyang · April 13, 2012 · Last by paranoyang replied at April 13, 2012 · 8129 hits

写了一篇博客详解了连接多个数据库的问题 How to Work With Two Different Databases in Rails - errno.me http://errno.me/blog/2012/04/16/how-to-work-with-two-different-databases-in-rails/ 希望能帮到大家吧;)

我需要在同一个 Rails 程序里访问两个不同的数据库中的数据,在 StackOerflow 找到该问题的三个解决方案: http://stackoverflow.com/questions/1226182/how-do-i-work-with-two-different-databases-in-rails-with-active-records ,其中第一种使用 connection_ninja,大概的代码如下

class KnowlegeBase < ActiveRecord::Base
  self.abstract_class = true
  use_connection_ninja(:knowlege_base)
end

class TKeywords < KnowlegeBase
end



在 database.yml 中加入:

knowlege_base:
  development:
    adpter: mysql2
    encoding: utf8
    reconnect: false
    database: test
    pool: 5
    username: root
    password:
    socket: /var/run/mysqld/mysqld.sock



这样当我在 rails c 中输入 TKeywords 时提示错误信息为:

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter



可是 adapter 明明就有嘛= =... StackOerflow 中的第三个答案(第二个跟第一个应该是一样的)尝试后也是同样的错误提示。无奈我对 ActiveRecord 理解不深,求助各位问题出在哪里?谢谢!

是不是 adapter 相关的 gem 没装 activerecord-mysql-adapter

#1 楼 @jiffies 这个是什么?貌似源里面没有饿...

抱歉是我二了,配置文件“adpter”.should == "adapter" XDXDXD..........

You need to Sign in before reply, if you don't have an account, please Sign up first.