如何在Activeadmin 中查看所有过滤记录?
How to check all filtered records in Activeadmin?
我已经按条件过滤了一些用户的记录。现在我想为所有人发送一封电子邮件,而不仅仅是第一页上的用户。如何查看所有过滤的用户?
类似于:
collection_action :check_filtered do |items|
items = collection
items.check_filtered
end
更新
希望经过大量阅读,我可以更加清楚。
如何访问过滤后的集合?
action_item(:index) do
link_to('notify filtered', notify_filtered_admin_users_path(params['q']))
end
收集操作中应该包含哪些内容才能将邮件发送给所有已过滤的用户?
问题已解决。 Here
应编辑此行:
instance_exec(resource_class.ransack(params[:q]).pluck(:id), options, &block)
至:
instance_exec(resource_class.ransack(params[:q]).result.pluck(:id), options, &block)
更新
这是与范围一起使用的扩展变体:
module ActiveAdmin
class DSL
def filtered_batch_action(title, options, &block)
self.batch_action title, options do |ids, options|
if params[:collection_selection_toggle_all] != "on"
instance_exec(ids, options, &block)
else
# pluck is ActiveRecord specific, probably needs abstracting
if params[:q].nil?
if params[:scope].nil?
instance_exec(resource_class.pluck(:id), options, &block)
else
instance_exec(resource_class.send(params[:scope]).pluck(:id), options, &block)
end
else
instance_exec(resource_class.ransack(params[:q]).result.send(params[:scope]).pluck(:id), options, &block)
end
end
end
end
end
end
我已经按条件过滤了一些用户的记录。现在我想为所有人发送一封电子邮件,而不仅仅是第一页上的用户。如何查看所有过滤的用户? 类似于:
collection_action :check_filtered do |items|
items = collection
items.check_filtered
end
更新 希望经过大量阅读,我可以更加清楚。
如何访问过滤后的集合?
action_item(:index) do
link_to('notify filtered', notify_filtered_admin_users_path(params['q']))
end
收集操作中应该包含哪些内容才能将邮件发送给所有已过滤的用户?
问题已解决。 Here 应编辑此行:
instance_exec(resource_class.ransack(params[:q]).pluck(:id), options, &block)
至:
instance_exec(resource_class.ransack(params[:q]).result.pluck(:id), options, &block)
更新 这是与范围一起使用的扩展变体:
module ActiveAdmin
class DSL
def filtered_batch_action(title, options, &block)
self.batch_action title, options do |ids, options|
if params[:collection_selection_toggle_all] != "on"
instance_exec(ids, options, &block)
else
# pluck is ActiveRecord specific, probably needs abstracting
if params[:q].nil?
if params[:scope].nil?
instance_exec(resource_class.pluck(:id), options, &block)
else
instance_exec(resource_class.send(params[:scope]).pluck(:id), options, &block)
end
else
instance_exec(resource_class.ransack(params[:q]).result.send(params[:scope]).pluck(:id), options, &block)
end
end
end
end
end
end