Class: Admin::SectionsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/sections_controller.rb

Direct Known Subclasses

PagesController

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin/sections_controller.rb', line 16

def create
  @section = @site.sections.build params[:section]
  if @section.save
    flash[:notice] = t(:'adva.sections.flash.create.success')
    redirect_to (params[:commit] == t(:'adva.sections.links.save_and_create_new') ? 
      [:new, :admin, @site, :section] :
      [:admin, @site, @section, :articles])
  else
    flash.now[:error] = t(:'adva.sections.flash.update.failure')
    render :action => "new"
  end
end

#destroyObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/sections_controller.rb', line 42

def destroy
  if @section.destroy
    flash[:notice] = t(:'adva.sections.flash.destroy.success')
    redirect_to [:new, :admin, @site, :section]
  else
    flash.now[:error] = t(:'adva.sections.flash.destroy.failure')
    render :action => 'edit'
  end
end

#editObject



29
30
# File 'app/controllers/admin/sections_controller.rb', line 29

def edit
end

#indexObject



8
9
10
# File 'app/controllers/admin/sections_controller.rb', line 8

def index
  @sections = @site.sections
end

#newObject



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

def new
  @section = @site.sections.build(:type => Section.types.first)
end

#updateObject



32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/sections_controller.rb', line 32

def update
  if @section.update_attributes params[:section]
    flash[:notice] = t(:'adva.sections.flash.update.success')
    redirect_to [:edit, :admin, @site, @section]
  else
    flash.now[:error] = t(:'adva.sections.flash.update.failure')
    render :action => 'edit'
  end
end

#update_allObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/admin/sections_controller.rb', line 52

def update_all
  params[:sections].each do |id, attrs|
    section = Section.find id
    if attrs[:parent_id].nil?
      section.move_to_root
    else
      section.move_to_child_of attrs[:parent_id]
    end
    section.move_to_right_of attrs[:left_id] if attrs[:left_id]
  end
  render :text => 'OK'
end