Class: Alchemy::PagesController

Inherits:
BaseController
  • Object
show all
Includes:
LegacyPageRedirects, LocaleRedirects, OnPageLayout::CallbacksRunner, PageRedirects, SiteRedirects
Defined in:
app/controllers/alchemy/pages_controller.rb

Instance Method Summary collapse

Methods included from Modules

included, #module_definition_for, register_module

Methods included from AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#indexObject

The index action gets invoked if one requests ‘/’ or ‘/:locale’

If the locale is the default locale, then it redirects to ‘/’ without the locale.

Loads the current language root page. The current language is either loaded via :locale parameter or, if that’s missing, the default language is used.

If this page is not published then it redirects to the first published descendant it finds.

If no public page can be found it renders a 404 error.



44
45
46
47
48
49
50
51
52
# File 'app/controllers/alchemy/pages_controller.rb', line 44

def index
  if Alchemy::Config.get(:redirect_index)
    ActiveSupport::Deprecation.warn("The configuration option `redirect_index` is deprecated and will be removed with the release of Alchemy v4.0")
    raise "Remove deprecated `redirect_index` configuration!" if Alchemy.version == "4.0.0.rc1"
    redirect_permanently_to page_redirect_url
  else
    show
  end
end

#showObject

The show action gets invoked if one requests ‘/:urlname’ or ‘/:locale/:urlname’

If the locale is the default locale, then it redirects to ‘/’ without the locale.

Loads the page via it’s urlname. If more than one language is published the current language is either loaded via :locale parameter or, if that’s missing, the page language is used and a redirect to the page with prefixed locale happens.

If the requested page is not published then it redirects to the first published descendant it finds. If no public page can be found it renders a 404 error.



65
66
67
68
69
70
71
72
# File 'app/controllers/alchemy/pages_controller.rb', line 65

def show
  if redirect_url.present?
    redirect_permanently_to redirect_url
  else
    authorize! :show, @page
    render_page if render_fresh_page?
  end
end

#sitemapObject

Renders a search engine compatible xml sitemap.



75
76
77
78
79
80
# File 'app/controllers/alchemy/pages_controller.rb', line 75

def sitemap
  @pages = Page.sitemap
  respond_to do |format|
    format.xml { render layout: 'alchemy/sitemap' }
  end
end