未定义的方法`解释'为#< ActiveRecord :: ConnectionAdapters :: MysqlAdapter [英] undefined method `explain' for #<ActiveRecord::ConnectionAdapters::MysqlAdapter

查看:121
本文介绍了未定义的方法`解释'为#< ActiveRecord :: ConnectionAdapters :: MysqlAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby on Rails的新手,但是我已经学习了一些教程并了解了一下我的方法。我已经生成了一些脚手架并将数据插入到MySql数据库中。



浏览到index.html.erb时,我收到标题错误

控制器正在执行索引

  def索引
@beers = Beer.all

respond_to do | format |
format.html#index.html.erb
format.json {render:json => @beers}
end
end

p>

 啤酒:id,brewer_id,名称,价格,分数,颜色,brew_type,create_at,updated_at 

RoR正在为我创建的其他脚手架工作,并列出数据。我在mysql中更新了实体Beer的结构,并且它可能没有反映rails的变化(dunno)。

我是否需要一个不同的gem来连接rails一个MySQL数据库?任何建议,以检查什么,将不胜感激(:/ b>

解决方案

我猜你正在使用Rails 3.2,您的 Beer.all 呼叫时间过长。从 3.2版本说明


运行时间超过半秒的查询自动为 在开发模式中进行了解释,当然这个阈值可以改变。

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html\">适用于Rails的MySQL适配器,没有 explain 方法。但是, , MySQL2适配器的确了解解释



首先,您可能需要更少的啤酒或者一些分页。然后,你应该尝试切换到MySQL2适配器;通过编辑你的 Gemfile 来使用 mysql2 ,运行 bundle 来设置新东西,然后将 database.yml 更改为如下所示:

 开发:
适配器:mysql2


I'm new to Ruby on Rails, but I have followed some tutorials and know my way around a little bit. I have generated some scaffolding and inserted data into a MySql database.

When navigating to index.html.erb I receive the error in the title

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. I updated the structure in mysql for the entity Beer, and it probably hasn't reflected changes in rails (dunno).

Do I need a different gem for connecting rails to a 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. From the 3.2 release notes:

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. However, the MySQL2 adapter does understand explain.

First of all, you probably need less beer or some pagination. Then, you should try switching to the MySQL2 adapter; 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:

development:
  adapter: mysql2

这篇关于未定义的方法`解释'为#< ActiveRecord :: ConnectionAdapters :: MysqlAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆