class ApplicationController
Public Instance Methods
authenticate_admin!()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 29 def authenticate_admin! return redirect_to new_user_session_path unless user_signed_in? redirect_to root_path unless current_user.admin? end
not_found(exception = nil)
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 18 def not_found(exception = nil) redirect = Redirector.find(request) if redirect redirect_to redirect else NotFoundNotifier.notify(request, exception) not_found_search_results if search_enabled? render_not_found end end
Private Instance Methods
locale_from_domain()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 82 def locale_from_domain if Rails.env.production? request.host == 'developer.nexmocn.com' ? 'cn' : 'en' else I18n.default_locale end end
not_found_search_results()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 59 def not_found_search_results parameters = ALGOLIA_CONFIG.keys.map do |index| { index_name: index, query: request.path.split('/').last.titleize, hitsPerPage: 5, } end @results = Algolia.multiple_queries(parameters) @results = JSON.parse(@results.to_json, object_class: OpenStruct).results end
page_title()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 90 def page_title @page_title ||= PageTitle.new(@product, @document_title).title end
render_not_found()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 72 def render_not_found render 'static/404', status: :not_found, formats: [:html] end
requires_authentication?()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 37 def requires_authentication? ENV['USERNAME'] && ENV['PASSWORD'] end
set_code_language()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 41 def set_code_language return unless request.params[:code_language] @code_language = Nexmo::Markdown::CodeLanguage.find(request.params[:code_language]) end
set_locale()
click to toggle source
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 76 def set_locale I18n.locale = params[:locale] || session[:locale] || locale_from_domain rescue I18n::InvalidLocale I18n.locale = I18n.default_locale end
set_notices()
click to toggle source
rubocop:disable Naming/MemoizedInstanceVariableName
# File lib/nexmo_developer/app/controllers/application_controller.rb, line 48 def set_notices @notices ||= LoadConfig.load_file('config/notices.yml') || {} end