Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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 (:

like image 959
italiansoda Avatar asked Jan 29 '12 23:01

italiansoda


People also ask

What is an undefined method?

The undefined method is also called the NoMethodError exception, and it's the most common error within projects, according to The 2022 Airbrake Error Data Report. It occurs when a receiver (an object) receives a method that does not exist.

What does it mean when you get this error message undefined method user for NILClass?

The Undefined method for nil:NILClass occurs when you attempt to use a formula on a blank datapill. This indicates that the datapill was not provided any value at runtime.

What is an undefined method in Ruby?

This is a common Ruby error which indicates that the method or attribute for an object you are trying to call on an object has not been defined. For example, the String class in Ruby has the method size (which is synonymous with length , so I can write...


1 Answers

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
like image 166
mu is too short Avatar answered Nov 11 '22 05:11

mu is too short