Skip to content

Commit 6b04454

Browse files
committed
Support proc in confirm option
Which allows to defer the content of the message, such as: scoped_collection_action :scoped_collection_export_csv, title: I18n.t('active_admin.actions.offers.export_csv'), confirm: lambda { I18n.t('active_admin.actions.offers.collection_export.confirm', offer_limit: Setting.offer_file_export_count_limit) } do In this example, Settings needs access to the database, and would be executed at startup if not using a proc.
1 parent 0c9d6a0 commit 6b04454

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/active_admin_scoped_collection_actions/resource_extension.rb

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def scoped_collection_actions_sidebar_section
6565
b_data[:inputs] = options[:form].is_a?(Proc) ? options[:form].call : options[:form]
6666
end
6767
b_data[:confirm] = options.fetch(:confirm, I18n.t('active_admin_scoped_collection_actions.confirm_action_message'))
68+
b_data[:confirm] = b_data[:confirm].call if b_data[:confirm].is_a?(Proc)
6869
b_options[:data] = b_data.to_json
6970
button b_title, b_options
7071
end

spec/posts_actions_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@
4141
end
4242
end
4343

44+
context 'scoped collection action DELETE' do
45+
before do
46+
page.find('#collection_actions_sidebar_section button', text: 'Delete').click
47+
end
48+
49+
context 'title' do
50+
it 'has predefined confirmation title' do
51+
expect(page).to have_css('.active_admin_dialog_mass_update_by_filter', text: 'Custom text for confirm delete all?')
52+
end
53+
end
54+
end
55+
4456
end

spec/support/admin.rb

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def add_post_resource(options = {}, &block)
3636
author_id: Author.all.map { |author| [author.name, author.id] }
3737
}
3838
}
39+
scoped_collection_action :scoped_collection_destroy,
40+
title: 'Delete',
41+
confirm: -> { 'Custom text for confirm delete all?' }
3942
end
4043

4144
Rails.application.reload_routes!

0 commit comments

Comments
 (0)