模型查询的 ArgumentError

ArgumentError on model query

我正在使用 ruby 2.1.5p273,Rails 4.2.3,但最近从更旧的版本升级。

我在 Phone 模型的这一行收到 "ArgumentError: wrong number of arguments (1 for 0)" 错误:

Phone.all(:joins => :phone_page, :conditions => [query, condition_values], :order => "date")

querycondition_values 存在。

谁能看出我做错了什么?是否应该在此处使用升级的语法?谢谢!

语法在 Rails 4 中发生了变化。现在您应该执行以下操作:

Phone.joins(:phone_page).where(query, condition_values).order(:date)

您应该重写此查询。解决方案之一是:

Phone.joins(:phone_page).where(query, condition_values).order('date')

另请参阅此处的 ActiveRecord 查询接口文档:

http://guides.rubyonrails.org/active_record_querying.html

.all 不带参数,参见 here。 Product.find(:all, your-arguments)

See related question here