Class: IshManager::EmailTemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/email_templates_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 4

def create
  authorize! :create, ::Ish::EmailTemplate
  template = ::Ish::EmailTemplate.create params[:ish_email_template].permit!
  if template.persisted?
    flash[:notice] = 'Success.'
  else
    flash[:alert] = "Could not create an email template: #{template.errors.full_messages.join(', ')}."
  end
  redirect_to action: :index
end

#destroyObject



15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 15

def destroy
  authorize! :destroy, ::Ish::EmailTemplate
  @template = Ish::EmailTemplate.where({ id: params[:id] }).first || Ish::EmailTemplate.find_by({ slug: params[:id] })
  if @template.destroy
    flash[:notice] = 'Success.'
  else
    flash[:alert] = 'Cannot destroy this template.'
  end
  redirect_to action: :index
end

#editObject



26
27
28
29
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 26

def edit
  @template = Ish::EmailTemplate.where({ id: params[:id] }).first
  authorize! :edit, @template
end

#iframe_srcObject



31
32
33
34
35
36
37
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 31

def iframe_src
  authorize! :iframe_src, Ish::EmailTemplate
  @email_template = Ish::EmailTemplate.where({ id: params[:id] }).first ||
    Ish::EmailTemplate.find_by({ slug: params[:id] })
  @email_ctx = EmailContext.new({ body: Ish::LoremIpsum.html })
  render layout: false
end

#indexObject



39
40
41
42
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 39

def index
  authorize! :index, Ish::EmailTemplate
  @templates = Ish::EmailTemplate.all.page( params[:templates_page] )
end

#showObject



44
45
46
47
48
49
50
51
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 44

def show
  authorize! :show, Ish::EmailTemplate
  @templates = Ish::EmailTemplate.all.page( params[:templates_page] )

  @email_template = Ish::EmailTemplate.where({ id: params[:id] }).first ||
    Ish::EmailTemplate.find_by({ slug: params[:id] })
  @email_ctx = EmailContext.new({ body: Ish::LoremIpsum.html })
end

#updateObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/ish_manager/email_templates_controller.rb', line 53

def update
  @template = Ish::EmailTemplate.where({ id: params[:id] }).first
  authorize! :update, @template
  flag = @template.update_attributes( params[:ish_email_template].permit! )
  if flag
    flash[:notice] = 'Success.'
    redirect_to action: 'index'
  else
    flash[:alert] = "No luck. #{@template.errors.full_messages.join(', ')}"
    render :edit
  end
end