mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FIX: Ensure load more directory items has a .json url
The `/directory_items` route needs to have a .json url, but the rails url helper `_path` doesn't return the format of the route. I tried passing in a format options to `directory_items_path`. Which works in the rails console ``` [8] pry(main)> directory_items_path(params.merge(:format => :json)) => "/directory_items.json?page=1" ``` but when I added that some logic to the controller it comes out as ``` /directory_items?format=json&page=1 ``` (which is actually how I expect it to work based on how you pass in the format param). Anyways, because I couldn't figure out how to pass a format to the `_path` helper I just used URI.parse to append `.json` manually.
This commit is contained in:
parent
c38212c73e
commit
ee366f7ac7
@ -65,6 +65,8 @@ class DirectoryItemsController < ApplicationController
|
||||
|
||||
more_params = params.slice(:period, :order, :asc).permit!
|
||||
more_params[:page] = page + 1
|
||||
load_more_uri = URI.parse(directory_items_path(more_params))
|
||||
load_more_directory_items_json = "#{load_more_uri.path}.json?#{load_more_uri.query}"
|
||||
|
||||
# Put yourself at the top of the first page
|
||||
if result.present? && current_user.present? && page == 0
|
||||
@ -84,7 +86,7 @@ class DirectoryItemsController < ApplicationController
|
||||
meta: {
|
||||
last_updated_at: last_updated_at,
|
||||
total_rows_directory_items: result_count,
|
||||
load_more_directory_items: directory_items_path(more_params)
|
||||
load_more_directory_items: load_more_directory_items_json
|
||||
}
|
||||
)
|
||||
end
|
||||
|
@ -50,6 +50,7 @@ describe DirectoryItemsController do
|
||||
|
||||
expect(json['directory_items'].length).to eq(4)
|
||||
expect(json['meta']['total_rows_directory_items']).to eq(4)
|
||||
expect(json['meta']['load_more_directory_items']).to include('.json')
|
||||
end
|
||||
|
||||
it "fails when the directory is disabled" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user