2014-01-16 34 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)