カスタム スコープで grouped_selects group_method を使用しようとしています。ユーザーは、自分が属しているプロジェクトとタスクのみを表示できます。
これは機能しています。選択するタスクを含むすべてのプロジェクトを取得しました:
# using simple_form
<%= f.input :project_id, :as => :grouped_select,
:collection => Project.my_scope(current_user),
:group_method => :tasks %>
これは機能していません。my_scope からタスクを取得しようとしています。
# using simple_form
<%= f.input :project_id, :as => :grouped_select,
:collection => Project.my_scope(current_user),
:group_method => Task.my_scope(current_user) %>
アップデート
Railsのデフォルトヘルパーでもこれを試しましたが、これはうまくいくようです:
<%= f.grouped_collection_select(:project_id,
Project.my_scope(current_user),
:"tasks.my_scope(#{current_user.id})",
:name, :id, :name) %>
これは一般的な方法ですか、それとも私のニーズを満たす他の方法はありますか?