2017-07-26 12 views
0

最近私のプロジェクトをrails3からrails4にアップグレードしました。私のモデルには以下のコードがあり、レールで失敗する4ArgumentError:Relation#countはfinderオプションをサポートしていません。 Rails 4

test_count = count(:all, :joins => joins, :conditions => conditions, :distinct => true) 

上記のコード行は、次のエラーを示します。

ArgumentError: Relation#count does not support finder options anymore. Please build a scope and then call count on it or use the activerecord-deprecated_finders gem to enable this functionality. 

レール4でこのエラーを解決するにはどうすればよいですか?

+1

これを 'test_count =(:all、:joins => join、:conditions =>条件、:distinct => true)に変更してみてください.count' – Pavan

+1

@pavanの提案が最適です。 'gem 'activerecord-deprecated_finders'、require: 'active_record/deprecated_finders'をgemfileに追加することができます。 – SteveTurczyn

+0

@pavanお返事ありがとうございます。この構文はもはやレール4でサポートされていないため、このソリューションはまだ失敗します。 – harika

答えて

0

IMOあなたのクエリは、このような何かに変換ありがとう:

joins(joins).where(conditions).distinct.count 

Active Record Query Interface程度Railsのガイドを見てください。

+0

ありがとうございます。この構文はうまくいった! – harika