gpt4 book ai didi

ruby-on-rails - 为需要身份验证的操作设计操作过滤器

转载 作者:行者123 更新时间:2023-12-04 01:38:53 26 4
gpt4 key购买 nike

我正在使用设计进行身份验证,但是我看不到用于指定需要用户登录的操作的操作过滤器,这是否包含在设计 gem 中?如果不是我怎么能创建一个,我有一个想法,但由于我是 Rails 的新手,我宁愿先从更有经验的程序员那里看到解决方案。

最佳答案

Devise Readme .

class PostsController < ApplicationController
respond_to :html

# Tell Devise that the #destroy action is
# special, and that the user must be
# authenticated in order to access the
# #desroy action.
# Note that the name of the method here,
# #authenticate_user!, depends on the
# particular class/table that you have
# set up to be managed with Devise.
before_filter :authenticate_user!,
:only => [:destroy]

before_filter :find_post!,
:only => [:destroy]

def destroy
@post.destroy
respond_with @post
end

private

def find_post!
@post = Post.find(params[:id])
end
end

关于ruby-on-rails - 为需要身份验证的操作设计操作过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4769402/

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