8000 feat: Customize the title in batch action. · activeadmin/activeadmin@7022e1f · GitHub
[go: up one dir, main page]

Skip to content

Commit 7022e1f

Browse files
committed
feat: Customize the title in batch action.
1 parent acbff01 commit 7022e1f

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

docs/9-batch-actions.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ en:
194194
publish: "Publish"
195195
```
196196
197+
### Customize the title
198+
199+
If you don't like to set the title by i18n, you also can customize them by passing `title` option.
200+
201+
So this:
202+
203+
```ruby
204+
ActiveAdmin.register Post do
205+
batch_action :publish, title: 'Publish the post' do |ids|
206+
# ...
207+
end
208+
end
209+
```
210+
197211
### Support for other index types
198212

199213
You can easily use `batch_action` in the other index views, *Grid*, *Block*,

lib/active_admin/dsl.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def batch_action(title, options = {}, &block)
109109

110110
# Either add/remove the batch action
111111
unless options == false
112+
# Customize the title
113+
title = options[:title] if options[:title]
114+
112115
config.add_batch_action(sym, title, options, &block)
113116
else
114117
config.remove_batch_action sym

spec/unit/dsl_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ def self.included(dsl)
7676
end
7777

7878
describe "#batch_action" do
79+
describe 'title of batch_action' do
80+
it 'default title' do
81+
dsl.run_registration_block do
82+
config.batch_actions = true
83+
batch_action :foo
84+
end
85+
expect(resource_config.batch_actions.first.title).to eq 'Foo'
86+
end
87+
88+
it 'default title' do
89+
dsl.run_registration_block do
90+
config.batch_actions = true
91+
batch_action :foo, title: 'Custom Foo'
92+
end
93+
expect(resource_config.batch_actions.first.title).to eq 'Custom Foo'
94+
end
95+
end
96+
7997
it "should add a batch action by symbol" do
8098
dsl.run_registration_block do
8199
config.batch_actions = true

0 commit comments

Comments
 (0)
0