Class: Rooler::TemplatesController

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

Instance Method Summary collapse

Methods included from ApplicationHelper

#liquidize, #render_tree

Instance Method Details

#createObject

POST /templates



47
48
49
50
51
52
53
54
55
# File 'app/controllers/rooler/templates_controller.rb', line 47

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



67
68
69
70
# File 'app/controllers/rooler/templates_controller.rb', line 67

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

#editObject

GET /templates/1/edit



43
44
# File 'app/controllers/rooler/templates_controller.rb', line 43

def edit
end

#indexObject

GET /templates



23
24
25
# File 'app/controllers/rooler/templates_controller.rb', line 23

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

#newObject

GET /templates/new



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

def new
  @template = Template.new
end

#showObject

GET /templates/1



28
29
30
31
32
33
34
35
# File 'app/controllers/rooler/templates_controller.rb', line 28

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



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/rooler/templates_controller.rb', line 10

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



58
59
60
61
62
63
64
# File 'app/controllers/rooler/templates_controller.rb', line 58

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