Files
mozo-backend/app/controllers/application_controller.rb
T
2012-11-27 14:19:37 +01:00

53 lines
1.2 KiB
Ruby

class ApplicationController < ActionController::Base
before_filter :set_locale
layout :layout_by_resource
protect_from_forgery
private
def set_locale
I18n.locale = :nl
end
def layout_by_resource
if devise_controller?
case session[:user_return_to]
when /\/user\// then 'phone'
when /obtain_token/ then 'obtain_token'
else 'theme1'
end
else
"application"
end
end
def check_active_list_state
if current_user.try(:active_list_id)
unless active_list.active?
current_user.list_is_closed!
redirect_to user_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
end
end
end
def active_list
return nil unless current_user.try(:active_list_id).present?
@active_list ||= List.find(current_user.active_list_id)
end
alias :active_list_object :active_list
helper_method :active_list_object
def js_alert(*args)
options = args.extract_options!
message = args.first || ''
{ok: false, message: message}.merge(options).to_json
end
def js_notice(*args)
options = args.extract_options!
message = args.first || ''
{ok: true, message: message}.merge(options).to_json
end
end