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:
@@ -10,11 +10,7 @@ class PostFlagsController < ApplicationController
|
||||
def index
|
||||
@post_flags = PostFlag.search(search_params).includes(:creator, post: [:flags, :uploader, :approver])
|
||||
@post_flags = @post_flags.paginate(params[:page], limit: params[:limit])
|
||||
respond_with(@post_flags) do |format|
|
||||
format.xml do
|
||||
render :xml => @post_flags.to_xml(:root => "post-flags")
|
||||
end
|
||||
end
|
||||
respond_with(@post_flags)
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
Reference in New Issue
Block a user