Ank*_*oni 4 authentication devise ruby-on-rails-3
我第一次使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1579 次 |
| 最近记录: |