运行rails服务器以进行关联时的弃用警告

时间:2013-10-01 08:10:29

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

我在Rails 4应用程序中使用letsrate gem。我已经将gem添加到我的lib文件中并对其进行了一些修改以使其与Rails 4一起使用。现在我收到了一个不赞成的警告:

DEPRECATION WARNING: The following options in your Performer.has_many :rates_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:76) DEPRECATION WARNING: The following options in your Performer.has_one :rate_average_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:79) DEPRECATION WARNING: The following options in your Performer.has_many :performance_rates declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:84) DEPRECATION WARNING: The following options in your Performer.has_one :performance_average declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:91)

产生此类错误的文件部分是:

module ClassMethods

def letsrate_rater
  has_many :ratings_given, :class_name => "Rate", :foreign_key => :rater_id       
end    

def letsrate_rateable(*dimensions)
  has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy, :conditions => {:dimension => nil}
  has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater  

  has_one :rate_average_without_dimension, :as => :cacheable, :class_name => "RatingCache", 
          :dependent => :destroy, :conditions => {:dimension => nil}


  dimensions.each do |dimension|        
    has_many :"#{dimension}_rates", :dependent => :destroy, 
                                   :conditions => {:dimension => dimension.to_s}, 
                                   :class_name => "Rate", 
                                   :as => :rateable

    has_many :"#{dimension}_raters", :through => "#{dimension}_rates", :source => :rater         

    has_one :"#{dimension}_average", :as => :cacheable, :class_name => "RatingCache", 
                                    :dependent => :destroy, :conditions => {:dimension => dimension.to_s}
  end                                                    
end

我尝试将:dependent =>:destroy添加到行的最后部分并更改条件=> {:dimension => dimension.to_s} to - > {:dimension => dimension.to_s}。它只会引发错误。我做错了什么?

2 个答案:

答案 0 :(得分:0)

尝试:

-> { where(:dimension => dimension.to_s)}

答案 1 :(得分:0)

范围(或lambda)必须是第二个参数,后跟一个选项哈希

has_one :rate_average_without_dimension, -> { where dimension: nil }, { :as => :cacheable, :class_name => "RatingCache", :dependent => :destroy }

has_one at APIDock