2014-01-16 59 views
0

嗨我的日誌文件中收到以下警告。因此,新手我想知道這是什麼警告,以及如何解決它。rails在我的日誌文件中獲取DEPRECATION警告

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 

請分不清什麼是我的問題是什麼原因造成了我所有的錯誤

回答

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]) 

有:

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

NK你現在我明白 – user3144005

1

我相信你應該把它用where代替find

rating = current_user.company_ratings.where(
      user_id: current_user.id, 
      company_id: company_id)