class RevelryContent::VersionsController < ApplicationController respond_to :json, :html include RevelryContent::ControllerAuthorization def info_for_paper_trail { rollback_version_id: params[:id] } end def index # Versions does not include the version, so grab versions, convert the # currents to mock versions, then combine and sort @versions = RevelryContent::ContentVersion.all @content = RevelryContent::Content.all.map { |content| RevelryContent::PseudoContentVersion.new model: content } @all_versions = (@content + @versions).sort { |a, b| b.created_at - a.created_at } respond_with @all_versions end def revert_all_to newer_versions = RevelryContent::ContentVersion.where('id >= ?', params[:id]).order('id desc') newer_versions.each do |version| if ['create', 'import create'].include? version.event unless version.id == params[:id].to_i item = version.item item.paper_trail_event = 'rollback create' version.item.destroy! end else reify = version.reify reify.paper_trail_event = "rollback #{ version.event }" reify.save! end end redirect_to :back end end