ita*_*oda 7 mysql rubygems ruby-on-rails ruby-on-rails-3.2 rails-activerecord
我是Ruby on Rails的新手,但我已经学过一些教程,并且知道我的方法.我已经生成了一些脚手架并将数据插入到MySql数据库中.
导航到index.html.erb时,我收到标题中的错误
控制器正在执行索引
def index
@beers = Beer.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @beers }
end
end
Run Code Online (Sandbox Code Playgroud)
并将此作为一种结构
Beer: id, brewer_id, name, price, score, color, brew_type, create_at, updated_at
Run Code Online (Sandbox Code Playgroud)
RoR正在为我创建的其他脚手架工作,并列出数据.我更新了实体Beer的mysql结构,它可能没有反映rails中的变化(dunno).
我是否需要一个不同的gem来将rails连接到mysql db?任何关于检查什么的建议都将受到赞赏(:
mu *_*ort 24
我猜你正在使用Rails 3.2并且你的Beer.all电话花了太长时间.从3.2发行说明:
在开发模式下会自动解释运行时间超过半秒的查询.当然,这个阈值可以改变.
如果我们查看Rails的MySQL适配器,就没有explain方法.但是,MySQL2适配器确实理解explain.
首先,你可能需要更少的啤酒或一些分页.然后,您应该尝试切换到MySQL2适配器; 只需通过编辑Gemfile使用来安装新的适配器mysql2,运行bundle以设置新的东西,然后将其更改database.yml为更像这样:
development:
adapter: mysql2
Run Code Online (Sandbox Code Playgroud)