Skip to content

Commit c7ea863

Browse files
Change default response format of the show action to HTML
This is consistent with the other actions. When making HTTP requests using tools that are not web browsers, like `curl` or `fetch` in JavaScript without an explicit `Accept` header Rails will receive the request as with the `Accept` header set to `*/*`. That means that all registered mime types are a potential match and Rails will pick the response type based on the order they're declared in the source code.
1 parent f4cf4b6 commit c7ea863

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/rails_admin/config/actions/show.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Show < RailsAdmin::Config::Actions::Base
2121
register_instance_option :controller do
2222
proc do
2323
respond_to do |format|
24-
format.json { render json: @object }
2524
format.html { render @action.template_name }
25+
format.json { render json: @object }
2626
end
2727
end
2828
end

spec/integration/actions/show_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
end
4848
end
4949

50+
context 'with default format' do
51+
it 'responds with HTML' do
52+
page.driver.options[:headers] = {'HTTP_ACCEPT' => '*/*'}
53+
visit show_path(model_name: 'team', id: team.id)
54+
55+
response_type = Mime::Type.parse(response_headers['Content-Type']).first
56+
expect(response_type).to be_html
57+
end
58+
end
59+
5060
context 'when compact_show_view is enabled' do
5161
it 'hides nil fields in show view by default' do
5262
visit show_path(model_name: 'team', id: team.id)

0 commit comments

Comments
 (0)