如何:在sign_in设计Rails之前要求管理员激活帐户

时间:2011-06-27 10:26:06

标签: ruby-on-rails-3 authentication login devise admin

我刚刚实现了一个功能,对我来说似乎是一个bug,当在设计认证中向用户表添加新列“Approved”时,我得到了甚至管理员必须被批准。这意味着我的管理员无法登录系统:)

这个功能的用途是什么?还有其他解决方案吗?

由于

1 个答案:

答案 0 :(得分:4)

在用户模型中执行类似的操作。

  # Devise overrides
  def disapprove 
    self.approved = false 
  end 
  def approve 
    self.approved = true 
  end 
  def active_for_authentication? 
    super && approved? 
  end 
  def inactive_message 
    approved? ? super : "Your account has not been approved" 
  end 
  # end Devise overrides

inactive_message内容将传递给Rails flash对象。确保默认情况下批准为false。