cancancan

    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熱度

    2回答

    我使用gem 'devise'和'cancancan'來定義用戶的角色。問題是,當我運行軌道服務器的說:undefined method 'admin?' for nil:NilClass ability.rb: class Ability include CanCan::Ability def initialize(user) if user.admin?

    -1熱度

    1回答

    我目前正在使用RoR構建類似自由職業者的網站,但我被卡住了某處,用設計生成的我的用戶表具有可以是管理員,客戶端或自由職業者。此外,我有一個屬於用戶的技能表,但我不希望每個用戶都具有技能,除了具有自由職業者角色的用戶,我如何去做這件事,目前我正在使用cancancan進行用戶授權和設計認證,是角色這樣或STI的最佳解決方案,以及如何將你建議我解決這個問題,這裏是一個示例代碼 class User <

    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 }

    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回答

    目前,我有一個可以完成所有工作的activeadmin管理員。但是,我希望有一個其他級別的管理員,除了添加/刪除/編輯新的管理員之外,其他任何人都可以完成任務你有一個簡單的方法來實現這個想法?

    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

    0熱度

    1回答

    這個測試用於工作,但我不明白爲什麼停止。現在,當我運行它時,other_user.profile等於零。 測試: require 'rails_helper' describe "User" do describe "abilities" do subject(:ability){ Ability.new(user) } let(:other_user) { nil }

    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