我在windows xp上,使用rails 3.1 我使用mysql2 0.2.6 但是当我 当我尝试提出如下请求时:
Product.all
我得到了回应:
irb(main):001:0> Product.all
←[1m←[36m (0.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35m (0.0ms)←[0m describe `products`
ArgumentError: wrong number of arguments (3 for 2)
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:634:in `select'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:470:in `find_by_sql'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation.rb:111:in `to_a'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:155:in `all'
from D:in `all'
from (irb):1
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from D:/projects/rails/_API/rake/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我的控制员:
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @products }
end
end
我的模特:
class Product < ActiveRecord::Base
define_index do
indexes brand
indexes name
indexes denomination
end
end
答案 0 :(得分:2)
mysql2 0.2.6与Rails 3.1不兼容。 您应该将Rails降级到3.0.7或将mysql2升级到0.3.1。