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 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
|