Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/generators/dummy/templates/controllers/application_controller.rb

Defined Under Namespace

Classes: PageNotFound

Instance Method Summary collapse

Instance Method Details

#available_rootsObject


58
59
60
# 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_classObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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_rootObject


19
20
21
22
23
24
25
26
27
28
# 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_404Object


11
12
13
# 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_localeObject


15
16
17
# File 'lib/generators/dummy/templates/controllers/application_controller.rb', line 15

def set_locale
  I18n.locale = params[:locale]
end

#siteObject


53
54
55
56
# 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_scopeObject


30
31
32
# File 'lib/generators/dummy/templates/controllers/application_controller.rb', line 30

def translation_scope
  "public." + self.class.name.gsub("Controller", "").underscore
end