Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change default response format of the show action to HTML
Browse files Browse the repository at this point in the history
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.
jacob-carlborg-apoex committed Dec 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f4cf4b6 commit a1f5bbb
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config/actions/show.rb
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ class Show < RailsAdmin::Config::Actions::Base
register_instance_option :controller do
proc do
respond_to do |format|
format.json { render json: @object }
format.html { render @action.template_name }
format.json { render json: @object }
end
end
end
10 changes: 10 additions & 0 deletions spec/integration/actions/show_spec.rb
Original file line number Diff line number Diff line change
@@ -47,6 +47,16 @@
end
end

context 'with default format' do
it 'responds with HTML' do
page.driver.options.merge!(headers: { 'HTTP_ACCEPT' => '*/*' })
visit show_path(model_name: 'team', id: team.id)

response_type = Mime::Type.parse(response_headers["Content-Type"]).first
expect(response_type).to be_html
end
end

context 'when compact_show_view is enabled' do
it 'hides nil fields in show view by default' do
visit show_path(model_name: 'team', id: team.id)

0 comments on commit a1f5bbb

Please sign in to comment.