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, #for_select

Methods inherited from ApplicationController

movable, #move_to

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/constructor_pages/templates_controller.rb', line 23

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



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

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



19
20
21
# File 'app/controllers/constructor_pages/templates_controller.rb', line 19

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

#indexObject



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

def index
  @templates_cache = Digest::MD5.hexdigest(@templates.map{|t| [t.id, t.name, t.lft]}.join)
end

#newObject



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

def new
  @template = Template.new
end

#updateObject



33
34
35
36
37
38
39
40
41
# File 'app/controllers/constructor_pages/templates_controller.rb', line 33

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