Class: ConstructorPages::TemplatesController

Inherits:
ApplicationController
  • Object
show all
Includes:
TreeviewHelper
Defined in:
app/controllers/constructor_pages/templates_controller.rb

Instance Method Summary collapse

Methods included from TreeviewHelper

#arrow_buttons_for, #render_tree

Methods inherited from ApplicationController

movable, #move_to

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/constructor_pages/templates_controller.rb', line 19

def create
  @template = Template.new template_params

  if @template.save
    redirect_to templates_url, notice: t(:template_success_added, name: @template.name)
  else
    render :new
  end
end

#destroyObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/constructor_pages/templates_controller.rb', line 39

def destroy
  @template = Template.find(params[:id])

  if @template.pages.count == 0
    name = @template.name
    @template.destroy
    redirect_to templates_url, notice: t(:template_success_removed, name: name)
  else
    redirect_to :back, alert: t(:template_error_delete_pages)
  end
end

#editObject



15
16
17
# File 'app/controllers/constructor_pages/templates_controller.rb', line 15

def edit
  @template = Template.find(params[:id])
end

#newObject



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

def new
  @template = Template.new
end

#updateObject



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

def update
  @template = Template.find params[:id]

  if @template.update template_params
    redirect_to templates_url, notice: t(:template_success_updated, name: @template.name)
  else
    render :edit
  end
end