Rails rails_admin 的用户身份不同,针对同一个 model,有不同的操作权限。

tracyzhang · April 09, 2015 · Last by jing replied at July 20, 2015 · 1819 hits

如题,比如我是超级管理员 我可以对 model 进行 index,new,edit,update 等所有操作。如果是一般管理员,只可以 index 操作。

在 rails_admin.rb 的配置文件中,有这么一段

config.actions do
  new do |variable|
    except ['Purchase']
  end
  dashboard                     # mandatory
  index                         # mandatory
  export
  bulk_delete
  show
  edit
  delete
  show_in_app

  ## With an audit adapter, you can add:
  history_index
  history_show
end

我现在只能把 purchase 这个 model 的 new 隐藏掉。但是不能针对 model 添加 admin 的判断。不知能否明白我的意思。有 wiki 说用 cancan 权限操作。但是我并不想为了这一个小逻辑而添加一个 gem。

fixed!我还是用了 cancan 解决了这个问题。 - - https://github.com/ryanb/cancan

以后不会再用它了

用 cancancan

You need to Sign in before reply, if you don't have an account, please Sign up first.