Skip to content

Commit

Permalink
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.
  • Loading branch information
jacob-carlborg-apoex committed Dec 19, 2024
1 parent f4cf4b6 commit c7ea863
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/actions/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
end
end

context 'with default format' do
it 'responds with HTML' do
page.driver.options[: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)
Expand Down

0 comments on commit c7ea863

Please sign in to comment.