В моем приложении у меня есть модель с именем User, которая имеет Tone.
В CanCanCan у меня есть эта способность:
class Ability
include CanCan::Ability
def initialize(user)
if user.nil?
can :read, User
can :read, Talent, is_public?: true
else
can :read, Talent, is_public?: true
end
Моя страница отображается с помощью ProfilesController # show. Как это:
class ProfilesController < ApplicationController
before_action :check_ability, except: [:show]
def show
@user = User.find(params[:id])
authorize! :read, @user
authorize! :read, @user.talent
if current_user
sent_connections = current_user.sent_connections
connections = sent_connections + current_user.all_connections
@is_connected = !(connections.select { |c| c.user.id == @user.id }.empty?)
end
@top_5_photos = @user.top_5_photos
end
Хорошо. Я пытаюсь сделать профиль, метод: is_public возвращает false. Но страница отображается правильно, хотя я ожидал, что пользователь не сможет увидеть страницу из-за правила:
can :read, Talent, is_public?: true
Что мне здесь не хватает?