我第一次将 Devise 与 Rails 结合使用,但遇到了一件事:
我使用了提供的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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)