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.
32 lines
836 B
Ruby
32 lines
836 B
Ruby
class PoolVersionsController < ApplicationController
|
|
respond_to :html, :xml, :json
|
|
before_action :check_availabililty
|
|
|
|
def index
|
|
if params[:search] && params[:search][:pool_id].present?
|
|
@pool = Pool.find(params[:search][:pool_id])
|
|
end
|
|
|
|
@pool_versions = PoolArchive.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
|
respond_with(@pool_versions)
|
|
end
|
|
|
|
def diff
|
|
@pool_version = PoolArchive.find(params[:id])
|
|
|
|
if params[:other_id]
|
|
@other_version = PoolArchive.find(params[:other_id])
|
|
else
|
|
@other_version = @pool_version.previous
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def check_availabililty
|
|
if !PoolArchive.enabled?
|
|
raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.")
|
|
end
|
|
end
|
|
end
|