Skip to content

Commit 95f9d20

Browse files
committed
2 parents 01ad42f + cdd6d2c commit 95f9d20

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/5-forms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ a thin DSL on top of [Formtastic](https://github.com/justinfrench/formtastic):
66
```ruby
77
ActiveAdmin.register Post do
88

9-
form do |f|
9+
form title: 'A custom title' do |f|
1010
inputs 'Details' do
1111
input :title
1212
input :published_at, label: "Publish Post At"

lib/active_admin/views/pages/form.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ module Pages
55
class Form < Base
66

77
def title
8-
assigns[:page_title] || I18n.t("active_admin.#{normalized_action}_model",
9-
model: active_admin_config.resource_label)
8+
if form_presenter[:title]
9+
render_or_call_method_or_proc_on(resource, form_presenter[:title])
10+
else
11+
assigns[:page_title] || I18n.t("active_admin.#{normalized_action}_model",
12+
model: active_admin_config.resource_label)
13+
end
1014
end
1115

1216
def form_presenter

spec/unit/views/pages/form_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
OpenStruct.new(params: params, helpers: helpers, assigns: {})
1717
end
1818

19+
context "when :title is set" do
20+
it "should show the set page title" do
21+
page = ActiveAdmin::Views::Pages::Form.new(arbre_context)
22+
expect(page).to receive(:resource)
23+
expect(page).to receive(:form_presenter).twice.and_return({ title: "My Page Title" })
24+
expect(page.title).to eq "My Page Title"
25+
end
26+
end
27+
1928
context "when page_title is assigned" do
2029
it "should show the set page title" do
2130
arbre_context.assigns[:page_title] = "My Page Title"

0 commit comments

Comments
 (0)