扶手:仅管理员维护模式 [英] Rails: admin-only maintenance mode

查看:259
本文介绍了扶手:仅管理员维护模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望把我的应用程序进入维护模式,但仍然有管理员/版主能够登录并使用该网站。有两个原因:

I'd like to put my app into maintenance mode but still have admins / moderators be able to log in and use the site. Two reasons:


  1. 我做的是使用在应用程序的接口,而不是控制台应用最好的应用程序中的一些变化。

  1. I'm making some changes within the app that are best applied using the in-app interface rather than the console.

版主没有进入到控制台,但可以用我们未来的维护任务一定帮助。

Moderators don't have access to the console, but can definitely help with the maintenance tasks we have ahead of us.

你会如何建议这样做吗?我一直在尝试设置环境变量 ADMIN_MODE 和更改所有权限时,这是事实,但这似乎pretty cludgy和缓慢的。

How would you recommend this be done? I have been experimenting with setting an environment variable ADMIN_MODE and changing all the permissions when it is true, but that seems pretty cludgy and slow.

我使用的康康舞和设计,为它的价值,但我肯定是开放给任何建议。

I'm using CanCan and Devise, for what it's worth, but I'm definitely open to any suggestions.

谢谢!

推荐答案

这可能会是一个相当简单的解决方案:

This would probably be a fairly simple solution:

class ApplicationController < ActionController::Base
  before_filter :check_admin_mode

  protected

  def check_admin_mode
    if ENV['ADMIN_MODE'] && controller_name != 'sessions' && !current_user.admin?
      redirect_to '/maintenance.html'
    end
  end
end

这篇关于扶手:仅管理员维护模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆