Sha256: c0ced8d08aebbb40b2680ea93cd8cdeaa91824af588cd9ee1a0f3ea437a696f3
Contents?: true
Size: 1.37 KB
Versions: 5
Compression:
Stored size: 1.37 KB
Contents
class CmsAdmin::SnippetsController < CmsAdmin::BaseController before_filter :build_cms_snippet, :only => [:new, :create] before_filter :load_cms_snippet, :only => [:edit, :update, :destroy] def index return redirect_to :action => :new if @cms_site.snippets.count == 0 @cms_snippets = @cms_site.snippets.all(:order => 'label') end def new render end def edit render end def create # raise @cms_snippet.to_yaml @cms_snippet.save! flash[:notice] = 'Snippet created' redirect_to :action => :edit, :id => @cms_snippet rescue ActiveRecord::RecordInvalid flash.now[:error] = 'Failed to create snippet' render :action => :new end def update @cms_snippet.update_attributes!(params[:cms_snippet]) flash[:notice] = 'Snippet updated' redirect_to :action => :edit, :id => @cms_snippet rescue ActiveRecord::RecordInvalid flash.now[:error] = 'Failed to update snippet' render :action => :edit end def destroy @cms_snippet.destroy flash[:notice] = 'Snippet deleted' redirect_to :action => :index end protected def build_cms_snippet @cms_snippet = @cms_site.snippets.new(params[:cms_snippet]) end def load_cms_snippet @cms_snippet = @cms_site.snippets.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:error] = 'Snippet not found' redirect_to :action => :index end end
Version data entries
5 entries across 5 versions & 1 rubygems