44 lines
1.0 KiB
Ruby
44 lines
1.0 KiB
Ruby
class ApplicationController < ActionController::Base
|
|
layout :layout_by_resource
|
|
|
|
|
|
protect_from_forgery
|
|
|
|
private
|
|
|
|
def layout_by_resource
|
|
if devise_controller?
|
|
"phone"
|
|
else
|
|
"application"
|
|
end
|
|
end
|
|
def check_active_list_state
|
|
if session[:active_list_id]
|
|
unless active_list.active?
|
|
session[:active_list_id] = nil
|
|
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 session[:active_list_id].present?
|
|
@active_list ||= List.find(session[: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
|