ruby-on-rails - 有没有办法将 "before_filter :authenticate_user!"与表中的 bool 值一起使用?

标签 ruby-on-rails devise

我正在使用 设计 .我加了一个 admin bool 列到我的 users table :

class AddAdminToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :admin, :boolean, :default => false
  end

  def self.down
    remove_column :users, :admin
  end
end

我只想允许管理员销毁用户。
设计的 before_filter :authenticate_user!通过仅允许登录用户执行操作来工作。有没有办法向 :authenticate_user 添加一些东西以便只有拥有 :admin => true 的用户可以执行一个 Action (例如销毁 Action )?

最佳答案

before_filter :authenticate_user!
before_filter :is_admin?

def is_admin?
  if current_user.admin?
    true
  else
    render :text => 'Who are you to doing this? :)'
  end
end

关于ruby-on-rails - 有没有办法将 "before_filter :authenticate_user!"与表中的 bool 值一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13170907/

相关文章:

ruby-on-rails - 在Rails应用中进行长轮询

ruby-on-rails - 如何通过 Rails 应用程序从 S3 代理文件以避免窃取?

ruby-on-rails - 设计超时错误显示 `true`

ruby-on-rails - Rails Admin - 成为另一个用户

ruby-on-rails - 根据环境覆盖 ActionMailer 中的字段

sql - 按字母顺序排列 ActiveRecord 结果

html - 想要在 Rails 中的每个页面上使用相同的横幅/导航菜单

mysql - rails 数据库 :migrate fails '[MODEL].users' doesn't exist: SHOW FULL FIELDS FROM `users`

ruby-on-rails - rails3,过滤器链停止为 :require_no_authentication rendered or redirected

ruby-on-rails - 设计:尝试设置用户名字段