【问题标题】:ActiveAdmin: how to only get current_user records in index pagesActiveAdmin:如何仅获取索引页面中的 current_user 记录
【发布时间】:2012-12-06 10:02:57
【问题描述】:

我在我的 rails 应用程序中安装了 ActiveAdmin,并且无法在索引页面中仅显示属于已登录用户的设备。

我有几个型号:
- 用户
- 组
- 设备

用户 has_and_belongs_to_many
设备 has_and_belongs_to_many

当用户登录时,我只需要属于索引中列出的用户组之一的设备。

我尝试在我的 activeadmin 的设备模型中修改控制器:

controller do
  def index
    index! do |format|
      @devices = current_user.is_admin? ? Device.all : current_user.groups.map{ |g| g.devices }.flatten.uniq
      format.html
    end
  end
end

但我最终得到以下错误:

# 的未定义方法“重新排序”

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 activeadmin


    【解决方案1】:

    我认为,你应该阅读这个问题。

    https://github.com/gregbell/active_admin/issues/1178

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 2020-09-19
      相关资源
      最近更新 更多