gpt4 book ai didi

ruby-on-rails-3 - 轨道与设计 : How to authenticate specific user?

转载 作者:行者123 更新时间:2023-12-03 00:31:31 25 4
gpt4 key购买 nike

我第一次将 Devise 与 Rails 结合使用,但遇到了一件事:我在用户 Controller 中使用了提供的 authenticate_user! 方法来限制对页面的访问,如下所示:before_filter :authenticate_user!, :only => [:edit, :show, :update, :create, :destroy]

但这允许任何登录用户访问任何其他用户 :edit 操作,我想仅限于该用户。我该怎么做?

最佳答案

在您的编辑方法中,您需要检查用户是否拥有该记录:

def edit
@record = Record.find(params[:id])
if @record.user == current_user
@record.update_attributes(params[:record])
else
redirect_to root_path
end
end

关于ruby-on-rails-3 - 轨道与设计 : How to authenticate specific user?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com