class ApplicationController

Public Instance Methods

available_roots() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 58
def available_roots
  @roots ||= node_class.roots.where(locale: I18n.available_locales, active: true)
end
node_class() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 34
def node_class
  if @node_class.blank?
    # this method detects whether the dummy application is running in a single or multiple node context
    routing = Releaf::Content.routing

    if routing.length == 1
      # for single node class site
      # the node class is the first and only defined class
      node_class = routing.keys.first.constantize
    else
      # for multinode sites
      # for non-node routes the node class can be detected from hostname via routing config
      node_class = Releaf::Content.routing.find { |node_class_name, options| request.host =~ options[:constraints][:host] }.first.constantize
    end
    @node_class = node_class
  end
  @node_class
end
redirect_to_locale_root() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 19
def redirect_to_locale_root
  # if no matching root found for any of client locales
  # use first root
  target_root = available_roots.first
  if target_root
    redirect_to target_root.path
  else
    render plain: "Welcome to Releaf", layout: true
  end
end
render_404() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 11
def render_404
  render file: Rails.root.join('public', '404.html'), status: 404, layout: nil
end
set_locale() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 15
def set_locale
  I18n.locale = params[:locale]
end
site() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 53
def site
  # for non-node routes site is detectable from node class via routing config
  @site = Releaf::Content.routing[node_class.name][:site]
end
translation_scope() click to toggle source
# File lib/generators/dummy/templates/controllers/application_controller.rb, line 30
def translation_scope
  "public." + self.class.name.gsub("Controller", "").underscore
end