0

Rails 4 アプリケーションでletsrate 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} を -> {:dimension => dimension.to_s} に変更しようとしました。エラーをスローするだけです。私は何を間違っていますか?

4

2 に答える 2

0

スコープ (またはラムダ) は、オプションのハッシュが続く 2 番目の引数でなければなりません

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

APIDock の has_one

于 2014-05-28T21:10:41.070 に答える
0

試す:

-> { where(:dimension => dimension.to_s)}
于 2013-10-01T08:37:45.543 に答える