导轨和放大器;设计:如何验证特定的用户?

编程入门 行业动态 更新时间:2024-10-09 10:29:02
本文介绍了导轨和放大器;设计:如何验证特定的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的设计首次使用Rails,和我有一件事情烦恼:我用所提供的的authenticate_user 方法在我的用户控制器来限制访问,像这样的网页!的before_filter:的authenticate_user!:只=>

I'm using Devise for the first time with rails, and I'm having trouble with one thing: I used the provided authenticate_user! method in my user's controller to restrict access to pages like so: before_filter :authenticate_user!, :only => [:edit, :show, :update, :create, :destroy]

但是,这允许任何登录的用户访问任何其他用户编辑动作,我想限制到只有该用户。我会怎么做呢?

But this allows any signed in user to access any other users :edit action, which I want to restrict to only that user. How would I do that?

推荐答案

在您的编辑方法,你需要做一个检查,以查看用户是否拥有记录:

In your edit method, you need to do a check to see if the user owns the record:

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

更多推荐

导轨和放大器;设计:如何验证特定的用户?

本文发布于:2023-06-02 19:17:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/457420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:导轨   放大器   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!