mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user