Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- protect_from_forgery # See ActionController::RequestForgeryProtection for details
- before_filter :user
- before_filter :set_locale
- # Scrub sensitive parameters from your log
- # filter_parameter_logging :password
- #
- # вывод результата в зависимости от необходимого формата
- def output (result)
- respond_to do |format|
- format.html {
- flash[:errors] = result[:errors] unless result[:errors].nil?
- redirect_to result[:redirect] unless result[:redirect].nil?
- }
- format.json {
- render :json => result[:errors].nil? ? result.to_json : { :errors => result[:errors] }
- }
- end
- end
- def user
- user = User.find(session[:user_id]) if session[:user_id]
- @user = user && user.email ? user : nil
- flash[:notice] = t(:hello)
- end
- private
- def set_locale
- I18n.locale = extract_locale_from_tld == 'com' ? 'en' : 'ru'
- logger.debug "LOCALE"+I18n.locale.to_s
- end
- def extract_locale_from_tld
- parsed_locale = request.host.split('.').last
- (['ru', 'com'].include?(parsed_locale)) ? parsed_locale : 'ru'
- end
- end
Add Comment
Please, Sign In to add comment