api: refactor default options for xml responses.
In xml responses, if the result is an empty array we want the response to look like this: <posts type="array"/> not like this (the default): <nil-classes type="array"/> This refactors controllers so that this is done automatically instead of having to manually call `@things.to_xml(root: "things")` everywhere. We do this by overriding the behavior of `respond_with` in `ApplicationResponder` to set the `root` option by default in xml responses.
This commit is contained in:
@@ -3,11 +3,7 @@ class NoteVersionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@note_versions = NoteVersion.search(search_params).paginate(params[:page], :limit => params[:limit])
|
||||
respond_with(@note_versions) do |format|
|
||||
format.html { @note_versions = @note_versions.includes(:updater) }
|
||||
format.xml do
|
||||
render :xml => @note_versions.to_xml(:root => "note-versions")
|
||||
end
|
||||
end
|
||||
@note_versions = @note_versions.includes(:updater) if request.format.html?
|
||||
respond_with(@note_versions)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user