rails在我的日志文件中获取DEPRECATION WARNING

时间:2014-01-16 22:25:09

标签: ruby-on-rails ruby-on-rails-4

您好我在我的日志文件中收到以下警告。因此新手我想知道这个警告是什么以及如何解决它。

DEPRECATION WARNING: Calling #find(:all) is deprecated. Please call #all directly instead. You have also used finder options. These are also deprecated. Please build a scope instead of using finder options. (called from user_rating at /home/raj/Desktop/webapp/app/controllers/company_ratings_controller.rb:73)
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from user_rating at /home/raj/Desktop/webapp/app/controllers/company_ratings_controller.rb:73)

这是我在73行的company_ratings_controller:

def user_rating   
    company_id = current_user.profile.companies.map(&:id)
    rating = current_user.company_ratings.find(:all,:conditions=>["user_id = ? and company_id IN (?)",current_user.id,company_id]) [line 73]

    end

请告诉我的问题是什么导致了我所有的错误

2 个答案:

答案 0 :(得分:1)

我认为您应该使用where而不是find

来调用它
rating = current_user.company_ratings.where(
           user_id: current_user.id,
           company_id: company_id)

答案 1 :(得分:1)

有关框架的弃用,更改和新增内容,请参阅“Ruby on Rails 4.0 Release Notes”。

要修复弃用,请使用user_rating方法替换以下行:

rating = current_user.company_ratings.find(:all,:conditions=>["user_id = ? and company_id IN (?)",current_user.id,company_id])

with:

rating = current_user.company_ratings.where("user_id = ? and company_id IN (?)",current_user.id,company_id)