diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 49b94e87..56c0b645 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -109,4 +109,20 @@ module ApplicationHelper end end + def page_path(record) + str = case record + when Page then record.name + else record + end + go_to_path(str, locale: I18n.locale) + end + + def find_page(name) + Page.find_by_name_and_locale(name, I18n.locale) + end + + def locale_root_path + I18n.locale == I18n.default_locale ? '/' : "/#{I18n.locale}" + end + end diff --git a/app/views/theme1/_navigation.html.slim b/app/views/theme1/_navigation.html.slim index 7afc4054..5f2eb7ad 100644 --- a/app/views/theme1/_navigation.html.slim +++ b/app/views/theme1/_navigation.html.slim @@ -5,8 +5,8 @@ span.icon-bar ul.nav - li[class=(current_page?(controller: '/pages', action: 'home') ? :active : nil)]= link_to t('menu.home'), root_path - li[class=(current_page?(controller: '/pages', action: 'show', name: 'about') ? :active : nil)]= link_to t('menu.about'), page_path('about') + li[class=(current_page?(controller: '/pages', action: 'home') ? :active : nil)]= link_to find_page('home').try(:menu_text), locale_root_path + li[class=(current_page?(controller: '/pages', action: 'show', name: 'about') ? :active : nil)]= link_to find_page('about').try(:menu_text), page_path('about') .nav-collapse.collapse ul.nav - Page.top_menu.each do |page| diff --git a/config/application.rb b/config/application.rb index 9c7eb046..a83ae7ae 100644 --- a/config/application.rb +++ b/config/application.rb @@ -50,7 +50,7 @@ module Qwaiter # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + config.i18n.default_locale = :nl # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/routes.rb b/config/routes.rb index 841cd5ee..cd161b2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -155,10 +155,10 @@ Qwaiter::Application.routes.draw do # just remember to delete public/index.html. # #root :to => 'dashboard#home' - root :to => 'pages#home' - - scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do - get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page + root :to => 'pages#home', defaults: {locale: 'nl'} + get '/:locale' => 'pages#home', constraints: {locale: /nl|be|de|fr|en/} + scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: 'nl' } do + get "/:name" => "pages#show", constraints: {name: /.*/}, as: :go_to end # See how all your routes lay out with "rake routes" diff --git a/spec/routing/locale_routing_spec.rb b/spec/routing/locale_routing_spec.rb new file mode 100644 index 00000000..651400c9 --- /dev/null +++ b/spec/routing/locale_routing_spec.rb @@ -0,0 +1,9 @@ +require "spec_helper" + +describe "routing" do + it('roots to pages#home'){get('/').should route_to('pages#home', locale: 'nl')} + it('roots to pages#home for en locale'){get('/en').should route_to('pages#home', locale: 'en')} + it('handles about page as root'){ get('/about').should route_to('pages#show', name: 'about', locale: 'nl')} + it('handles about page in nl'){ get('/nl/about').should route_to('pages#show', name: 'about', locale: 'nl')} + it('handles about page in en'){ get('/en/about').should route_to('pages#show', name: 'about', locale: 'en')} +end