Class: Odania::MenuController

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

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/odania/menu_controller.rb', line 5

def index
	accepted_langs = current_site.menus.map { |o| o.language.iso_639_1 }
	locale = http_accept_language.preferred_language_from(accepted_langs)
	language = Odania::Language.where(iso_639_1: locale).first if locale.nil?
	language = current_site.default_language if language.nil?
	menu = current_site.menus.where(language_id: language.id).first

	return render_not_found if menu.nil?
	redirect_to menu.get_target_path
end


16
17
18
19
20
21
22
23
24
# File 'app/controllers/odania/menu_controller.rb', line 16

def menu_index
	menu_item = current_menu.default_menu_item unless current_menu.default_menu_item_id.nil?
	menu_item = current_menu.menu_items.where(parent_id: nil).first if menu_item.nil?

	return render_error(t('No content defined')) if menu_item.nil?

	return redirect_to menu_item.target_data['url'] if 'URL'.eql? menu_item.target_type
	redirect_to menu_item.get_target_path
end

#show_pageObject



26
27
28
29
30
# File 'app/controllers/odania/menu_controller.rb', line 26

def show_page
	# Try to find the correct menu_item
	menu_item = current_menu.menu_items.where(full_path: params[:path]).first
	display_menu_item(menu_item)
end