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:
@@ -78,11 +78,7 @@ private
|
||||
@posts = @posts.includes(comments: [:creator])
|
||||
@posts = @posts.includes(comments: [:votes]) if CurrentUser.is_member?
|
||||
|
||||
respond_with(@posts) do |format|
|
||||
format.xml do
|
||||
render :xml => @posts.to_xml(:root => "posts")
|
||||
end
|
||||
end
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
def index_by_comment
|
||||
@@ -91,9 +87,6 @@ private
|
||||
format.atom do
|
||||
@comments = @comments.includes(:post, :creator).load
|
||||
end
|
||||
format.xml do
|
||||
render :xml => @comments.to_xml(:root => "comments")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user