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.
24 lines
730 B
Ruby
24 lines
730 B
Ruby
class WikiPageVersionsController < ApplicationController
|
|
respond_to :html, :xml, :json
|
|
|
|
def index
|
|
@wiki_page_versions = WikiPageVersion.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
|
respond_with(@wiki_page_versions)
|
|
end
|
|
|
|
def show
|
|
@wiki_page_version = WikiPageVersion.find(params[:id])
|
|
respond_with(@wiki_page_version)
|
|
end
|
|
|
|
def diff
|
|
if params[:thispage].blank? || params[:otherpage].blank?
|
|
redirect_back fallback_location: wiki_pages_path, notice: "You must select two versions to diff"
|
|
return
|
|
end
|
|
|
|
@thispage = WikiPageVersion.find(params[:thispage])
|
|
@otherpage = WikiPageVersion.find(params[:otherpage])
|
|
end
|
|
end
|