cancancan

    2热度

    2回答

    我使用gem 'devise'和'cancancan'来定义用户的角色。问题是,当我运行轨道服务器的说:undefined method 'admin?' for nil:NilClass ability.rb: class Ability include CanCan::Ability def initialize(user) if user.admin?

    0热度

    1回答

    使用cancancan的最基本的实现,觉得我疯了。 下面是在我的用户模型 ROLES = %i[admin regular reporter] # Roles logic to covert string above to/from integers def roles=(roles) roles = [*roles].map { |r| r.to_sym }

    0热度

    1回答

    目前,我有一个可以完成所有工作的activeadmin管理员。但是,我希望有一个其他级别的管理员,除了添加/删除/编辑新的管理员之外,其他任何人都可以完成任务你有一个简单的方法来实现这个想法?

    0热度

    2回答

    我想要定义一种能力,其中登录的参与者可以根据邀请来管理项目。下面 代码时,我访问项目undefined method project' for #<Project:0x007f2c998410> can :manage, Project, :project=>{:invite=>{:participant=>{:user => {:id => user.id}}}} TL产生错误; DR 表关

    0热度

    1回答

    我有一个问题,同时定义用户和ClassD之间的关联深入的能力。 User < ActiveRecord::Base has_many :classB has_many :classC, through classB has_many :classD, through classB end ClassB < ActiveRecord::Base belon

    -1热度

    1回答

    我目前正在使用RoR构建类似自由职业者的网站,但我被卡住了某处,用设计生成的我的用户表具有可以是管理员,客户端或自由职业者。此外,我有一个属于用户的技能表,但我不希望每个用户都具有技能,除了具有自由职业者角色的用户,我如何去做这件事,目前我正在使用cancancan进行用户授权和设计认证,是角色这样或STI的最佳解决方案,以及如何将你建议我解决这个问题,这里是一个示例代码 class User <

    0热度

    1回答

    这个测试用于工作,但我不明白为什么停止。现在,当我运行它时,other_user.profile等于零。 测试: require 'rails_helper' describe "User" do describe "abilities" do subject(:ability){ Ability.new(user) } let(:other_user) { nil }

    1热度

    1回答

    我已经宣布在cancancan宝石作用的能力(导轨5,Postgres的,设计): can [:update, :show, :destroy, :index], SalesDatum do |datum| datum.try(:user_id) == user.id #the ids just access the id's from the user object that is p

    2热度

    1回答

    我有2个表格:帖子和用户(他们的关系是多对多),用户有很多favorite_posts(与FavoritePost表(它由user_id和post_id组成) 所以,我有路线: 获得 'favorite_posts',到: 'favorite_posts#指数' (用户/:USER_ID/favorite_posts) 在我ability.rb: class Ability includ

    0热度

    1回答

    我正在寻找测试CanCanCan gem消息的方式。 def my authorize! :my_words, word, message: I18n.t("messages.login_to_add_new_word") end 有点像? it "sets flash message" do expect(message???).to eq I18n.t("messag