2017-11-01 1 views
0

私は5.1をレールにし、間違っているかを把握することはできませんアップグレードした後に、このエラーを取得しています:のRails 5.1:#<ActiveRecordは::アソシエーションの未定義のメソッド `apply_scope」:: AssociationScope

undefined method `apply_scope' for #<ActiveRecord::Associations::AssociationScope 

関連するコードを次のとおりです。

def set_site 
    @site = current_account.sites.active.find(params[:id]) 
    redirect_to sites_path if @site.nil? 
    @site 
end 

モデル:

class Site < ApplicationRecord 
    belongs_to :account 
    scope :active, (-> { where(workflow_state: 'active') }) 
    # .... 
end 

フルスタックトレース:

composite_primary_keys (10.0.1) lib/composite_primary_keys/associations/association_scope.rb:35:in `block in last_chain_scope' 
composite_primary_keys (10.0.1) lib/composite_primary_keys/associations/association_scope.rb:33:in `each' 
composite_primary_keys (10.0.1) lib/composite_primary_keys/associations/association_scope.rb:33:in `last_chain_scope' 
activerecord (5.1.0) lib/active_record/associations/association_scope.rb:126:in `add_constraints' 
/usr/local/bundle/bundler/gems/activemodel-associations-8dab1043fc77/lib/active_model/associations/association_scope_extension.rb:10:in `add_constraints' 
activerecord (5.1.0) lib/active_record/associations/association_scope.rb:28:in `scope' 
activerecord (5.1.0) lib/active_record/associations/association_scope.rb:5:in `scope' 
activerecord (5.1.0) lib/active_record/associations/association.rb:97:in `association_scope' 
activerecord (5.1.0) lib/active_record/associations/collection_proxy.rb:1162:in `association_scope' 
activerecord (5.1.0) lib/active_record/associations/collection_proxy.rb:1131:in `method_missing' 
app/controllers/sites_controller.rb:215:in `set_site' 

答えて

0

apply_scopeRails 5.2の新しい方法であるように見える:彼らがした以前のバージョンにしながら

def apply_scope(scope, table, key, value) 
    if scope.table == table 
    scope.where!(key => value) 
    else 
    scope.where!(table.name => { key => value }) 
    end 
end 

scope = scope.where(table.name => { key => value }) 

だから私はあなたがRailsの5.xのがインストールされている、と仮定しますが、 Rails 5.2メソッドを呼び出す。その場合、gemfileを確認してbundle show railsを実行して、使用しているRubyとRuby on Railsのバージョンを確認してください。

関連する問題