Reputation: 736
I've filtered some user's records by criteria. Now I want to send an email for all of them, not only for users that are on first page. How to check all filtered users? Something like:
collection_action :check_filtered do |items|
items = collection
items.check_filtered
end
Update After a lot of reading I can be more clear, I hope.
How can I access filtered collection?
action_item(:index) do
link_to('notify filtered', notify_filtered_admin_users_path(params['q']))
end
What should be in collection action to send mails to all filtered users?
Upvotes: 0
Views: 426
Reputation: 736
The problem is solved. Here This line should be edited:
instance_exec(resource_class.ransack(params[:q]).pluck(:id), options, &block)
to:
instance_exec(resource_class.ransack(params[:q]).result.pluck(:id), options, &block)
UPDATE Here is extended variant for using with scopes:
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
Upvotes: 1