Class: Rooler::TemplatesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rooler/templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /templates



44
45
46
47
48
49
50
51
52
# File 'app/controllers/rooler/templates_controller.rb', line 44

def create
  @template = Template.new(template_params)

  if @template.save
    redirect_to @template, notice: 'Template was successfully created.'
  else
    render action: 'new'
  end
end

#destroyObject

DELETE /templates/1



64
65
66
67
# File 'app/controllers/rooler/templates_controller.rb', line 64

def destroy
  @template.destroy
  redirect_to templates_url, notice: 'Template was successfully destroyed.'
end

#editObject

GET /templates/1/edit



40
41
# File 'app/controllers/rooler/templates_controller.rb', line 40

def edit
end

#indexObject

GET /templates



20
21
22
# File 'app/controllers/rooler/templates_controller.rb', line 20

def index
  @templates = Template.order(:created_at)
end

#newObject

GET /templates/new



35
36
37
# File 'app/controllers/rooler/templates_controller.rb', line 35

def new
  @template = Template.new
end

#showObject

GET /templates/1



25
26
27
28
29
30
31
32
# File 'app/controllers/rooler/templates_controller.rb', line 25

def show
  test_object = @template.test_object
  if test_object
    @liquid_variables = {test_object.class.name.demodulize.downcase.to_s => test_object}
  else
    flash.now[:notice] ||= "Variables may be empty. Searched the rules associated with this template but couldn't find any objects to test with."
  end
end

#testObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/rooler/templates_controller.rb', line 7

def test
  test_object = @template.test_object
  deliverable = Delivery.new(deliverable: test_object, template: @template) if test_object
  delivery = DeliveryMailer.send_mail(deliverable, params[:email]).deliver if deliverable
  if delivery
    redirect_to @template, notice: "Test email sent"
  else
    notice = test_object ? "Failed. Couldn't deliver email" : "Failed. Searched the rules associated with this template but couldn't find any objects to test with."
    redirect_to @template, notice: notice
  end
end

#updateObject

PATCH/PUT /templates/1



55
56
57
58
59
60
61
# File 'app/controllers/rooler/templates_controller.rb', line 55

def update
  if @template.update(template_params)
    redirect_to @template, notice: 'Template was successfully updated.'
  else
    render action: 'edit'
  end
end