Guest User

Untitled

a guest
Apr 26th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. # Filters added to this controller apply to all controllers in the application.
  2. # Likewise, all the methods added will be available for all controllers.
  3.  
  4. class ApplicationController < ActionController::Base
  5. helper :all # include all helpers, all the time
  6. protect_from_forgery # See ActionController::RequestForgeryProtection for details
  7. before_filter :user
  8. before_filter :set_locale
  9.  
  10. # Scrub sensitive parameters from your log
  11. # filter_parameter_logging :password
  12. #
  13.  
  14. # вывод результата в зависимости от необходимого формата
  15. def output (result)
  16. respond_to do |format|
  17. format.html {
  18. flash[:errors] = result[:errors] unless result[:errors].nil?
  19. redirect_to result[:redirect] unless result[:redirect].nil?
  20. }
  21. format.json {
  22. render :json => result[:errors].nil? ? result.to_json : { :errors => result[:errors] }
  23. }
  24. end
  25. end
  26.  
  27. def user
  28. user = User.find(session[:user_id]) if session[:user_id]
  29. @user = user && user.email ? user : nil
  30. flash[:notice] = t(:hello)
  31. end
  32.  
  33. private
  34. def set_locale
  35. I18n.locale = extract_locale_from_tld == 'com' ? 'en' : 'ru'
  36. logger.debug "LOCALE"+I18n.locale.to_s
  37. end
  38.  
  39. def extract_locale_from_tld
  40. parsed_locale = request.host.split('.').last
  41. (['ru', 'com'].include?(parsed_locale)) ? parsed_locale : 'ru'
  42. end
  43.  
  44. end
Add Comment
Please, Sign In to add comment