我正在使用 设计 .我加了一个 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/