Class: ConstructorPages::TemplatesController

Inherits:
ConstructorCore::AdminController
  • Object
show all
Includes:
ConstructorCore::DeviseHelper
Defined in:
app/controllers/constructor_pages/templates_controller.rb

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object



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

def create
  @template = Template.new params[:template]

  if @template.save
    redirect_to templates_url, :notice => "Шаблон «#{@template.name}» успешно добавлен."
  else
    render :action => "new"
  end
end

#destroy ⇒ Object



45
46
47
48
49
50
# File 'app/controllers/constructor_pages/templates_controller.rb', line 45

def destroy
  @template = Template.find(params[:id])
  name = @template.name
  @template.destroy
  redirect_to templates_url, :notice => "Шаблон «#{name}» успешно удален."
end

#edit ⇒ Object



21
22
23
# File 'app/controllers/constructor_pages/templates_controller.rb', line 21

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

#move_down ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'app/controllers/constructor_pages/templates_controller.rb', line 62

def move_down
  from = Template.find(params[:id])
  rs = from.right_sibling
  if not rs.nil? and from.move_possible?(rs)
    from.move_right
  end

  redirect_to :back
end

#move_up ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'app/controllers/constructor_pages/templates_controller.rb', line 52

def move_up
  from = Template.find(params[:id])
  ls = from.left_sibling
  if not ls.nil? and from.move_possible?(ls)
    from.move_left
  end

  redirect_to :back
end

#new ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/controllers/constructor_pages/templates_controller.rb', line 12

def new
  @template = Template.new

  if params[:template]
    @parent = Template.find(params[:template])
    @template.parent_id = @parent.id
  end
end

#update ⇒ Object



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

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

  if @template.update_attributes params[:template]
    redirect_to templates_url, :notice => "Шаблон «#{@template.name}» успешно обновлен."
  else
    render :action => "edit"
  end
end