Sha256: 70fd8e70f8434510e4b52fe70ed9bffa75744bd124f7fedf3b43001a0275ed26
Contents?: true
Size: 1.67 KB
Versions: 9
Compression:
Stored size: 1.67 KB
Contents
class CmsAdmin::SnippetsController < CmsAdmin::BaseController before_filter :build_snippet, :only => [:new, :create] before_filter :load_snippet, :only => [:edit, :update, :destroy] def index return redirect_to :action => :new if @site.snippets.count == 0 @snippets = @site.snippets.includes(:categories).for_category(params[:category]) end def new render end def edit render end def create @snippet.save! flash[:notice] = I18n.t('cms.snippets.created') redirect_to :action => :edit, :id => @snippet rescue ActiveRecord::RecordInvalid logger.detailed_error($!) flash.now[:error] = I18n.t('cms.snippets.creation_failure') render :action => :new end def update @snippet.update_attributes!(params[:snippet]) flash[:notice] = I18n.t('cms.snippets.updated') redirect_to :action => :edit, :id => @snippet rescue ActiveRecord::RecordInvalid logger.detailed_error($!) flash.now[:error] = I18n.t('cms.snippets.update_failure') render :action => :edit end def destroy @snippet.destroy flash[:notice] = I18n.t('cms.snippets.deleted') redirect_to :action => :index end def reorder (params[:cms_snippet] || []).each_with_index do |id, index| if (cms_snippet = Cms::Snippet.find_by_id(id)) cms_snippet.update_attribute(:position, index) end end render :nothing => true end protected def build_snippet @snippet = @site.snippets.new(params[:snippet]) end def load_snippet @snippet = @site.snippets.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:error] = I18n.t('cms.snippets.not_found') redirect_to :action => :index end end
Version data entries
9 entries across 9 versions & 1 rubygems