gpt4 book ai didi

mysql - #
转载 作者:可可西里 更新时间:2023-11-01 06:34:40 24 4
gpt4 key购买 nike

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

导航到 index.html.erb 时,我收到标题中的错误

Controller 正在执行索引

  def index
@beers = Beer.all

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

并将其作为结构

Beer: id, brewer_id, name, price, score, color, brew_type, create_at, updated_at

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

我需要一个不同的 gem 来将 rails 连接到 mysql 数据库吗?任何关于检查内容的建议将不胜感激(:

最佳答案

我猜您正在使用 Rails 3.2,并且您的 Beer.all 调用花费的时间太长。来自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.

如果我们看一下 MySQL adapter for Rails , 没有 explain 方法。然而,MySQL2 adapter确实理解解释

首先,您可能需要更少的啤酒或一些分页。然后,您应该尝试切换到 MySQL2 适配器;只需通过编辑 Gemfile 来安装新的适配器以使用 mysql2,运行 bundle 来设置新的东西,然后更改您的 database.yml 看起来更像这样:

development:
adapter: mysql2

关于mysql - #<ActiveRecord::ConnectionAdapters::MysqlAdapter 的未定义方法 `explain',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9057863/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com