我第一次将 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/