Class: CmsAdmin::SnippetsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/cms_admin/snippets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
# File 'app/controllers/cms_admin/snippets_controller.rb', line 20

def create
  @cms_snippet.save!
  flash[:notice] = 'Snippet created'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to create snippet'
  render :action => :new
end

#destroyObject



38
39
40
41
42
# File 'app/controllers/cms_admin/snippets_controller.rb', line 38

def destroy
  @cms_snippet.destroy
  flash[:notice] = 'Snippet deleted'
  redirect_to :action => :index
end

#editObject



16
17
18
# File 'app/controllers/cms_admin/snippets_controller.rb', line 16

def edit
  render
end

#indexObject



7
8
9
10
# File 'app/controllers/cms_admin/snippets_controller.rb', line 7

def index
  return redirect_to :action => :new if @cms_site.cms_snippets.count == 0
  @cms_snippets = @cms_site.cms_snippets.all(:order => 'label')
end

#newObject



12
13
14
# File 'app/controllers/cms_admin/snippets_controller.rb', line 12

def new
  render
end

#updateObject



29
30
31
32
33
34
35
36
# File 'app/controllers/cms_admin/snippets_controller.rb', line 29

def update
  @cms_snippet.update_attributes!(params[:cms_snippet])
  flash[:notice] = 'Snippet updated'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to update snippet'
  render :action => :edit
end