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:
@@ -5,11 +5,7 @@ class PostVersionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@post_versions = PostArchive.includes(:updater, post: [:versions]).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
respond_with(@post_versions) do |format|
|
||||
format.xml do
|
||||
render xml: @post_versions.to_xml(root: "post-versions")
|
||||
end
|
||||
end
|
||||
respond_with(@post_versions)
|
||||
end
|
||||
|
||||
def search
|
||||
|
||||
Reference in New Issue
Block a user