You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
class Admins :: BaseController < ApplicationController
include Base :: PaginateHelper
include Admins :: RenderHelper
include Base :: ErrorRescueHandler
layout 'admin'
skip_before_action :verify_authenticity_token
before_action :require_login , :require_admin!
after_action :rebind_event_if_ajax_render_partial
private
def require_login
return if User . current . logged?
redirect_to " /login?back_url= #{ CGI :: escape ( request . fullpath ) } "
end
def require_admin!
return if current_user . blank? || ! current_user . logged?
return if current_user . admin_or_business?
render_forbidden
end
# 触发after ajax render partial hooks, 执行一些因为局部刷新后失效的绑定事件
def rebind_event_if_ajax_render_partial
return if request . format . symbol != :js
return if response . content_type != 'text/javascript'
path = Rails . root . join ( 'app/views/admins/shared/after_render_js_hook.js.erb' )
return unless File . exists? ( path )
append_js = ERB . new ( File . open ( path ) . read ) . result
response . body += append_js
end
end