Class: SiteMenusController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#is_current_user?

Instance Method Details

- (Object) create



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

def create
  @site_menu = SiteMenu.create(params[:site_menu])
  if @site_menu.save
    redirect_to site_menus_path, :notice => t(:site_menu_successfully_created)
  else
    render :new
  end
end

- (Object) destroy



40
41
42
43
# File 'app/controllers/site_menus_controller.rb', line 40

def destroy
  @site_menu.delete
  redirect_to site_menus_path, :notice => t(:site_menu_deleted)
end

- (Object) edit



28
29
# File 'app/controllers/site_menus_controller.rb', line 28

def edit
end

- (Object) index



7
8
9
10
# File 'app/controllers/site_menus_controller.rb', line 7

def index
  authorize! :read, SiteMenu
  @site_menus = SiteMenu.roots
end

- (Object) new



12
13
14
15
16
17
# File 'app/controllers/site_menus_controller.rb', line 12

def new
  if params[:parent]
    parent = SiteMenu.find(params[:parent])
    @site_menu = parent.children.build()
  end
end

- (Object) sort_menus



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/site_menus_controller.rb', line 45

def sort_menus
  if params[:site_menu].present?
    update_site_menu_position(params[:site_menu],SiteMenu.roots)
  else
    params.each do |key, values|
      id = key.gsub(/site_menu_children_of_/,"")
      update_site_menu_position(values,SiteMenu.find(id).children)
      break
    end
  end
  render :nothing => true
end

- (Object) update



31
32
33
34
35
36
37
38
# File 'app/controllers/site_menus_controller.rb', line 31

def update
  if @site_menu.update_attributes(params[:site_menu])
    redirect_to site_menus_path, :notice => t(:site_menu_successfully_updated)
  else
    flash[:alert] = t(:site_menu_could_not_be_updated)
    render :edit
  end
end