Class: Comfy::Admin::Cms::SnippetsController

Inherits:
BaseController
  • Object
show all
Includes:
ReorderAction
Defined in:
app/controllers/comfy/admin/cms/snippets_controller.rb

Instance Method Summary collapse

Methods included from ReorderAction

#reorder

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 25

def create
  @snippet.save!
  flash[:success] = I18n.t("comfy.admin.cms.snippets.created")
  redirect_to action: :edit, id: @snippet
rescue ActiveRecord::RecordInvalid
  flash.now[:danger] = I18n.t("comfy.admin.cms.snippets.creation_failure")
  render action: :new
end

#destroyObject



43
44
45
46
47
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 43

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

#editObject



21
22
23
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 21

def edit
  @snippet.attributes = snippet_params
end

#indexObject



12
13
14
15
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 12

def index
  return redirect_to action: :new if @site.snippets.count.zero?
  @snippets = @site.snippets.includes(:categories).for_category(params[:categories]).order(:position)
end

#newObject



17
18
19
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 17

def new
  render
end

#updateObject



34
35
36
37
38
39
40
41
# File 'app/controllers/comfy/admin/cms/snippets_controller.rb', line 34

def update
  @snippet.update!(snippet_params)
  flash[:success] = I18n.t("comfy.admin.cms.snippets.updated")
  redirect_to action: :edit, id: @snippet
rescue ActiveRecord::RecordInvalid
  flash.now[:danger] = I18n.t("comfy.admin.cms.snippets.update_failure")
  render action: :edit
end