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.
educoder/app/controllers/concerns/admins/render_helper.rb

47 lines
1.3 KiB

module Admins::RenderHelper
extend ActiveSupport::Concern
def render_forbidden
respond_to do |format|
format.html { redirect_to '/403' }
format.json { super }
end
end
def render_not_found
respond_to do |format|
format.html { render 'admins/shared/404' }
format.js { render_js_error('资源未找到') }
format.json { render status: 404, json: { message: '资源未找到' } }
end
end
def render_unprocessable_entity(message)
respond_to do |format|
format.html { render 'admins/shared/422' }
format.js { render_js_error(message) }
format.json { render status: 422, json: { message: message } }
end
end
alias_method :render_error, :render_unprocessable_entity
def internal_server_error
respond_to do |format|
format.html { render 'admins/shared/500' }
format.js { render_js_error(message) }
format.json { render status: 500, json: { message: '系统错误' } }
end
end
def render_js_template(template, **opts)
render({ template: template, formats: :js }.merge(opts))
end
def render_delete_success
render_js_template 'admins/shared/delete'
end
def render_js_error(message)
render_js_template 'admins/shared/error', locals: { message: message }
end
end