私は許可のためにcancanを使用しています。ユーザーがプロフィール/ユーザーページにアクセスしたときに他のユーザーを見ることができないようにしたいと思います。ユーザーは自分自身を見ることができます。私はCancanユーザーの許可ですか?
class UsersController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
def index
@user = current_user
end
def show
@user = User.find(params[:id])
end
end
以上を持って、私は私のusers_controllerで
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.role? :admin
can :manage, :all
elsif user.role? :rookie
can [:update, :destroy], [Album, Photo, User]
can :read, :all
end
can :manage, Album, :profile => { :user_id => user.id }
can :manage, Photo, :profile => { :user_id => user.id }
can :manage, Video, :profile => { :user_id => user.id }
can :manage, Comment, :blog => { :profile => { :user_id => user.id } }
can :manage, User, :id => user.id
end
end
を持っている私のability.rbファイルで
通常動作しますが、ユーザーは私が解決できるか確認していない主要なモデルであるため、この。 Railsはそれがあるべき私にエラー
undefined method `user_id'
が動作しましたが、私は他人のユーザーを見ることができますか?助言がありますか? – coletrain
あなたの役割は何ですか? –
私の役割は新人と管理者 – coletrain