私に親切に助言を与えることができました - 非常に感謝します。私のusers_controller.rbファイルには、edit action
の中に条件文があります。私は、コードcurrent_user.company == @user.company && current_user.firstname == @user.firstname
のこのラインを書くためにしたいと思い、私モデルのcurrent_userとuser_idを比較する方法 - Rails4
users_controller.rbファイルにuser.rbモデルファイルからメソッド
profile_editing_rights
呼び出すしたいと思いますusers_controller.rb
def edit
if current_user.company == @user.company && current_user.firstname == @user.firstname
# can edit only their profile
else
redirect_to access_restricted_path
end
end
user.rbモデルファイルしかし、私は以下試みたが、動作しませんどのように
わからない午前:
def profile_editing_rights
self.company == user_id.company && self.firstname == user_id.firstname
end
1は親切に私は以下のようにusers_controller.rbファイル でそれを呼び出すことができるように正しく(user.rbファイル内)
profile_editing_rights
メソッドを作成する方法を私に助言することができます:
def edit
if current_user.profile_editing_rights
# can edit only their profile
else
redirect_to access_restricted_path
end
end
を
はるかにUSER_IDが整数で、オブジェクトではないようだ
ヤホールが示唆しているように、それを前のフィルターに入れてください。フィルタの内部でリダイレクトを処理することもできます。 – venkatKA