如何检查Rails 3.2是否可以连接MySQL?
是否有一种简单的“命令行/控制台”方法来检查 Rails 应用程序是否正确连接到 MySQL?
不幸的是,我无法启动 Rails 控制台。它抱怨:
/home/nexargi/www/gi/vendor/ruby/1.9.1/gems/activerecord-3.2.1/lib
/active_record/dynamic_matchers.rb:50:in `method_missing': undefined
local variable or method `abddadhocbkgid' for #<Class:0x000000036427f8> (NameError)
from /home/nexargi/www/gi/app/models/adhoc_bkg_diners_diet.rb:5:in
`<class:AdhocBkgDinersDiet>'.
“abddadhocbkid”是第一个表的第一个属性,因此我认为它无法连接到 mysql 数据库。我需要找到一种方法来检查 Rails 是否可以在不登录 Rails 控制台的情况下连接到 mysql 数据库。
这是我的模型代码:
class AdhocBkgDinersDiet < ActiveRecord::Base
validates_presence_of :abddadhocbkgid, :abddmealdietid, :abddadultnos, :abddchildnos
validates_numericality_of :abddadultnos, :abddchildnos, greater_than_or_equal_to: 0
belongs_to :adhoc_bkg, foreign_key:abddadhocbkgid
belongs_to :meal_diet, foreign_key: :abddmealdietid
end
Is there an easy 'command line/console' way of checking if a Rails app is connecting properly to MySQL?
Unfortunately, I can't get a Rails console to come up. It complains about:
/home/nexargi/www/gi/vendor/ruby/1.9.1/gems/activerecord-3.2.1/lib
/active_record/dynamic_matchers.rb:50:in `method_missing': undefined
local variable or method `abddadhocbkgid' for #<Class:0x000000036427f8> (NameError)
from /home/nexargi/www/gi/app/models/adhoc_bkg_diners_diet.rb:5:in
`<class:AdhocBkgDinersDiet>'.
The 'abddadhocbkid' is the first attribute of the first table and therefore I am thinking that it is not managing to connect to the mysql database. I need to find a way of checking if Rails can connect to the mysql database without logging into the rails console.
Here is my model code:
class AdhocBkgDinersDiet < ActiveRecord::Base
validates_presence_of :abddadhocbkgid, :abddmealdietid, :abddadultnos, :abddchildnos
validates_numericality_of :abddadultnos, :abddchildnos, greater_than_or_equal_to: 0
belongs_to :adhoc_bkg, foreign_key:abddadhocbkgid
belongs_to :meal_diet, foreign_key: :abddmealdietid
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要检查连接建立后是否处于活动状态,可以使用
ActiveRecord::Base.connected?
方法。If you just need to check if your connection is active after it has been established, there is the
ActiveRecord::Base.connected?
method.您可以尝试直接使用控制台连接:
或者如果您有模型,您可以尝试查找一个:
You can try connecting directly using console:
Or if you have a model you can try finding one: