在我的 ability.rb
,我有以下规则:
elsif user.has_role? :demo
can :read, Profile, demo_featured: true, demo_linked: true, message: "To access this profile, please subscribe here."
但这不会产生我想要的信息。
如何获得此特定规则以生成我想要的消息?
编辑 1
这是完整的
ability.rb
if
健康)状况: def initialize(user)
user ||= User.new # guest user (not logged in)
alias_action :create, :show, :new, :destroy, to: :csnd
if user.has_role? :admin
can :manage, :all
elsif user.has_role? :coach
# do some stuff
elsif user.has_role? :demo
can :read, Profile, demo_featured: true, demo_linked: true
elsif user.has_role? :player
# can do some stuff
else
can :read, Profile
end
end
这些是我的
ProfilesController
中的一些内容: before_action :set_profile, only: [:show, :edit, :update, :destroy, :invite_user, :profiles]
def set_profile
@profile = Profile.published.includes(:grades, :positions, :achievements, :videos, :transcripts).friendly.find(params[:id])
end
最佳答案
关于ruby-on-rails - 如何从我的 ability.rb 中指定自定义异常消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41096174/