Class: ApplicationController

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

Overview

The main application controller for RLetters

This controller implements functionality shared throughout the entire RLetters site.

Instance Method Summary collapse

Instance Method Details

#devise_parameter_sanitizerDevise::ParameterSanitizer (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Send the right parameter sanitizers to Devise

Devise in Rails 4 uses this hook in the application controller in order to determine which parameters are accepted across the various account management forms. When a regular user logs in, delegate to that parameter sanitizer. Otherwise (e.g., for admin logins in the backend), just use the defaults.

This method is not tested, as it's only ever called from within the internals of Devise.

:nocov:

Returns:

  • (Devise::ParameterSanitizer)

    sanitizer to be used



87
88
89
90
91
92
93
# File 'app/controllers/application_controller.rb', line 87

def devise_parameter_sanitizer
  if resource_class == User
    User::ParameterSanitizer.new(User, :user, params)
  else
    super
  end
end

#ensure_trailing_slashundefined (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Make sure there's a trailing slash on the URL

jQuery Mobile really wants us always to have a trailing slash on our URLs, since we often are redirecting to subdirectory pages (e.g., from /datasets/ to /datasets/2/ to /datasets/2/task/3/results/, etc.). This helper makes sure we've always got a trailing slash. Don't disable it!

Returns:

  • (undefined)


55
56
57
58
# File 'app/controllers/application_controller.rb', line 55

def ensure_trailing_slash
  redirect_to url_for(params.merge(trailing_slash: true)),
              status: 301 unless trailing_slash?
end

#set_localeundefined (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the locale if the user is logged in

This function is called as a before_filter in all controllers, you do not need to call it yourself. Do not disable it, or the locale system will go haywire.

Returns:

  • (undefined)


22
23
24
25
26
27
28
# File 'app/controllers/application_controller.rb', line 22

def set_locale
  if user_signed_in?
    I18n.locale = current_user.language.to_sym
  else
    I18n.locale = I18n.default_locale
  end
end

#set_timezoneundefined (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the timezone if the user is logged in

This function is called as a before_filter in all controllers, you do not need to call it yourself. Do not disable it, or the timezone system will go haywire.

Returns:

  • (undefined)


38
39
40
41
42
43
44
# File 'app/controllers/application_controller.rb', line 38

def set_timezone
  if user_signed_in?
    Time.zone = current_user.timezone
  else
    Time.zone = 'Eastern Time (US & Canada)'
  end
end

#trailing_slash?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Does the URL end with a trailing slash?

Returns:

  • (Boolean)

    true if request URL ends with /



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

def trailing_slash?
  # If fullpath isn't defined (e.g., in testing), then just return true
  # so we don't do unnecessary redirects.
  return true if request.env['REQUEST_URI'].blank?

  request.env['REQUEST_URI'].match(/[^\?]+/).to_s.last == '/'
end