为需要身份验证的操作设计操作筛选器

ryu*_*ice 11 authentication authorization ruby-on-rails devise

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

yfe*_*lum 23

请参阅设计自述文件.

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
Run Code Online (Sandbox Code Playgroud)