Class: Admin::TemplatesController

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

Overview

This controller manage the admin views for Template model

Instance Method Summary collapse

Methods inherited from ApplicationController

#default_url_options, #new_session_path

Instance Method Details

#createObject

POST /admin/templates or /admin/templates.json



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

def create
  @template = Template.new(template_params)
  if @template.update(template_params)
    @component =  Admin::Templates::DetailComponent
  else
    @component =  Admin::Templates::EditComponent
  end
  render turbo_stream: turbo_stream.replace("new_template", @component.new(template: @template))
end

#destroyObject

DELETE /admin/templates/1 or /admin/templates/1.json



50
51
52
53
54
55
56
57
# File 'app/controllers/admin/templates_controller.rb', line 50

def destroy
  @template.destroy!

  respond_to do |format|
    format.html { redirect_to admin_templates_url, notice: "Template was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /admin/templates/1/edit



25
26
# File 'app/controllers/admin/templates_controller.rb', line 25

def edit
end

#indexObject

GET /admin/templates or /admin/templates.json



6
7
8
9
# File 'app/controllers/admin/templates_controller.rb', line 6

def index
  @text = [ "title ilike :text", { text: "%#{filter_params[:text]}%" } ] if filter_params[:text].present?
  @pagy, @templates = pagy Template.where(@text)
end

#newObject

GET /admin/templates/new



16
17
18
19
20
21
22
# File 'app/controllers/admin/templates_controller.rb', line 16

def new
  @template = Template.new
  respond_to do |format|
    format.html { redirect_to admin_templates_path }
    format.turbo_stream { render turbo_stream: turbo_stream.prepend("templates_list", Admin::Templates::EditComponent.new(template: @template)) }
  end
end

#showObject

GET /admin/templates/1 or /admin/templates/1.json



12
13
# File 'app/controllers/admin/templates_controller.rb', line 12

def show
end

#updateObject

PATCH/PUT /admin/templates/1 or /admin/templates/1.json



40
41
42
43
44
45
46
47
# File 'app/controllers/admin/templates_controller.rb', line 40

def update
  if @template.update(template_params)
    @component =  Admin::Templates::DetailComponent
  else
    @component =  Admin::Templates::EditComponent
  end
  render turbo_stream: turbo_stream.replace("template_#{@template.id}", @component.new(template: @template))
end