Devise action filter for actions that require authentication

后端 未结 2 1458
天涯浪人
天涯浪人 2021-02-20 02:29

I\'m using devise for authentication, however I cant see and action filter for specifying actions that require the user to login, is this included in the devise gem? if not how

相关标签:
2条回答
  • 2021-02-20 02:49

    The other solution is to use for example :except => login, its using when the entire app use authentication and you want to have a page with public access

    0 讨论(0)
  • 2021-02-20 03:00

    See the 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
    
    0 讨论(0)
提交回复
热议问题