Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#current_navableObject

This method returns the navable object the navigational elements on the currently shown page point to.

For example, if the bread crumb navigation reads ‘Start > Intranet > News’, the current_navable would return the with ‘News’ associated navable object.

This also means, that the current_navable has to be set in the controller through point_navigation_to.



43
44
45
# File 'app/controllers/application_controller.rb', line 43

def current_navable
  @navable
end

#current_navable=(navable) ⇒ Object

This method sets the currently shown navable object. Have a look at #current_navable.



50
51
52
# File 'app/controllers/application_controller.rb', line 50

def current_navable=( navable )
  @navable = navable
end

#current_userObject

This method returns the currently signed in user.



30
31
32
# File 'app/controllers/application_controller.rb', line 30

def current_user
  .user if 
end

#point_navigation_to(navable) ⇒ Object



53
54
55
# File 'app/controllers/application_controller.rb', line 53

def point_navigation_to( navable )
  self.current_navable = navable
end

#redirect_www_subdomainObject

Redirect the www subdomain to non-www, e.g. www.example.com to example.com.



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/application_controller.rb', line 60

def redirect_www_subdomain
  if (request.host.split('.')[0] == 'www') and (not Rails.env.test?)
    # A flash cross-domain flash message would only work if the cookies are shared between the subdomains.
    # But we won't make this decision for the main app, since this can be a security risk on shared domains.
    # More info on sharing the cookie: http://stackoverflow.com/questions/12359522/
    #
    flash[:notice] = I18n.t(:you_may_leave_out_www)
    redirect_to "http://" + request.host.gsub('www.','')
  end
end

#set_localeObject

The locale of the application s set as follows:

1. Use the url parameter 'locale' if given.
2. Use the language of the web browser if supported by the app.
3. Use the default locale if no other could be determined.


76
77
78
79
80
81
# File 'app/controllers/application_controller.rb', line 76

def set_locale
  cookies[:locale] = secure_locale_param if params[:locale].present?
  cookies[:locale] = nil if params[:locale] and params[:locale] == ""
  cookies[:locale] = nil if cookies[:locale] == ""
  I18n.locale = cookies[:locale] || browser_language_if_supported_by_app || I18n.default_locale
end