[英]undefined method `explain' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter
I'm new to Ruby on Rails, but I have followed some tutorials and know my way around a little bit. 我是Ruby on Rails的新手,但我已经学过一些教程,并且知道我的方法。 I have generated some scaffolding and inserted data into a MySql database.
我已经生成了一些脚手架并将数据插入到MySql数据库中。
When navigating to index.html.erb I receive the error in the title 导航到index.html.erb时,我收到标题中的错误
The controller is executing index 控制器正在执行索引
def index
@beers = Beer.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @beers }
end
end
And has this as a structure 并将此作为一种结构
Beer: id, brewer_id, name, price, score, color, brew_type, create_at, updated_at
RoR is working for other scaffolding I have created, and listing data. RoR正在为我创建的其他脚手架工作,并列出数据。 I updated the structure in mysql for the entity Beer, and it probably hasn't reflected changes in rails (dunno).
我更新了实体Beer的mysql结构,它可能没有反映rails中的变化(dunno)。
Do I need a different gem for connecting rails to a mysql db? 我是否需要一个不同的gem来将rails连接到mysql db? Any advice on what to check for would be appreciated (:
任何关于检查什么的建议都将受到赞赏(:
I'm guessing that you're using Rails 3.2 and that your Beer.all
call is taking too long. 我猜你正在使用Rails 3.2并且你的
Beer.all
通话耗时太长。 From the 3.2 release notes : 从3.2发行说明 :
Queries that take more than half a second to run are automatically explained in the development mode.
在开发模式下会自动解释运行时间超过半秒的查询。 This threshold, of course, can be changed.
当然,这个阈值可以改变。
And if we look at the MySQL adapter for Rails , there is no explain
method. 如果我们查看Rails的MySQL适配器 ,就没有
explain
方法。 However, the MySQL2 adapter does understand explain
. 但是, MySQL2适配器确实理解
explain
。
First of all, you probably need less beer or some pagination. 首先,你可能需要更少的啤酒或一些分页。 Then, you should try switching to the MySQL2 adapter;
然后,您应该尝试切换到MySQL2适配器; just install the new adapter by editing your
Gemfile
to use mysql2
, run bundle
to get the new stuff set up, and then change your database.yml
to look more like this: 只需通过编辑
Gemfile
来安装新的适配器以使用mysql2
,运行bundle
来设置新的东西,然后将database.yml
更改为更像这样:
development:
adapter: mysql2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.