class PublicationsController < ApplicationController unloadable def create if unpublished_resource.publish! flash[:notice] = I18n.t('flash.publications.create.notice', :default => "#{resource.class.human_name} published successfully") else flash[:resource] = resource end respond_to do |format| format.html {redirect_to :back} end end def destroy if published_resource.unpublish! flash[:notice] = I18n.t('flash.publications.destroy.notice', :default => "#{resource.class.human_name} unpublished successfully") end respond_to do |format| format.html {redirect_to :back} end end protected def unpublished_resource @resource ||= resource_class.unpublished.find(params[:id]) end def published_resource @resource ||= resource_class.published.find(params[:id]) end def resource @resource end def resource_class params[:resource].camelize.constantize end end