【问题标题】:ArgumentError at /user. - Rails 4 Rails_admin Pundit/user 处的参数错误。 - Rails 4 Rails_admin 权威
【发布时间】:2016-05-24 03:21:59
【问题描述】:

我正在尝试使用 rails_admin_pundit 添加基于角色的访问权限 到 rails_admin。

单击 rails_admin 中的用户表时出现此错误。

ArgumentError at /user. User(id: integer, email: string, ... 'shortened' ...role: integer) is not an ActiveRecord::Relation

我使用以下代码创建了一个应用:
https://github.com/RailsApps/rails-devise-pundit

并遵循以下使用说明:
https://github.com/sudosu/rails_admin_pundit

这是我的user_policy.rb,只是为了让事情开始......

def rails_admin?(action)
  case action
    when :destroy, :new
      false
    else
      @current_user.admin!
  end
end

附件是几个出现错误的应用程序,以及我在按下用户型号名称链接之前看到的屏幕截图。

app with the error..

error file and screenshot

another app with the same error

不需要:保管箱链接... link to screenshot, error page, and two apps that I have this problem in...

  • 我可以让专家在 rails_admin 之外工作
  • 我以管理员身份登录
  • 我已在网上搜索此错误或类似问题。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: ruby-on-rails devise rails-admin pundit


    【解决方案1】:

    当我们生成我们拥有的代码时:

    class Scope < Scope
        def resolve
          scope
        end
      end
    

    所以,我们需要定义范围

    class Scope < Scope
      def resolve      
        if @user.role.description == 'admin' 
          User.all
        else
          User.where(id: @user.id)
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      相关资源
      最近更新 更多