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



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

def create
  @snippet.save!
  flash[:success] = 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

#destroyObject



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

def destroy
  @snippet.destroy
  flash[:success] = I18n.t('cms.snippets.deleted')
  redirect_to :action => :index
end

#editObject



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

def edit
  render
end

#indexObject



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

def index
  return redirect_to :action => :new if @site.snippets.count == 0
  @snippets = @site.snippets.includes(:categories).for_category(params[:category])
end

#newObject



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

def new
  render
end

#reorderObject



45
46
47
48
49
50
# File 'app/controllers/cms_admin/snippets_controller.rb', line 45

def reorder
  (params[:cms_snippet] || []).each_with_index do |id, index|
    Cms::Snippet.where(:id => id).update_all(:position => index)
  end
  render :nothing => true
end

#updateObject



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

def update
  @snippet.update_attributes!(params[:snippet])
  flash[:success] = 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