【发布时间】:2018-10-20 09:12:42
【问题描述】:
我刚开始使用 Ruby on Rails 进行开发,我正在寻找一个动态授权插件,它使管理员能够将权限与角色相关联,并将角色与用户相关联。
我在 stackoverflow 和一些论坛上找到了一些帖子,在 railscasts.org 也找到了一些针对这个主题的播客,但它们都提到 acl9、declarative_authorization、Aegis、restful acl 甚至 Authlogic,这不是授权而是身份验证插入。其他的不提供所需的功能。
那么有人可以告诉我是否可以使用 ruby on rails 设置 Web 界面来管理用户角色?
所以现在我使用以下迁移迁移了我的数据库。
class AddRolesAndRightsTables < ActiveRecord::Migration
def self.up
create_table :roles_users do |t|
t.integer :role_id
t.integer :user_id
end
create_table :roles do |t|
t.string :name
end
create_table :rights_roles do |t|
t.integer :right_id
t.integer :role_id
end
create_table :rights do |t|
t.string :name
t.string :controller
t.string :action
end
end
def self.down
drop_table :roles_users
drop_table :roles
drop_table :rights_roles
drop_table :rights
end
end
除了一些视图和控制器动作之外,我还向 ApplicationController 添加了以下动作。
def check_authorization
user = User.find(session[:user])
unless user.roles.detect do |role|
role.rights.select do |right|
right.action == action_name && right.controller == self.class.controller_path
end
end
redirect_back_or user
flash[:notice] = "You are not authorized to view the page you requested."
return false
end
运行 Right.synchronize_with_controllers(请参阅 Wolfman-Blog 的博客帖子),我收到以下错误。
syntax error, unexpected $end, expecting kEND (line 17 in application_controller)
【问题讨论】:
标签: ruby-on-rails dynamic authorization