2016-06-02 7 views
0

のスコープはdoneです。 TaskProjectUserに属します。スコープによるRansackの検索

完了したプロジェクトでユーザーをフィルタリングする必要があります。task

simple_form_for @q do |form| 
    form.input :tasks_done_project_id, collection: Project.ordered 

ただし、 "_done"を使用すると機能しません。

私はransackerについて考えた:

ransacker :done do |parent| 
    parent.done.table[:id] 
    end 

しかし、どちらも動作しません。何か案が? the doumentationから

答えて

0

デフォルトでは、検索やソートはあなたのモデルのいずれかの列に許可されていると何のクラスメソッド/スコープは、ホワイトリストに登録されていません。あなたのTaskモデルで

...

# `ransackable_scopes` by default returns an empty array 
# i.e. no class methods/scopes are authorized. 
# For overriding with a whitelist array of *symbols*. 
# 
def ransackable_scopes(auth_object = nil) 
    [] 
end 

、明示的done範囲をホワイトリストに登録する必要があります。

class Task < ActiveRecord::Base 
    scope :done, -> { ... } 

    def self.ransackable_scopes(auth_object = nil) 
    [:done] 
    end 
end 
関連する問題