복붙노트

[RUBY-ON-RAILS] 어떻게 레일의 특정 작업에 대한 토큰 인증을 무시합니까?

RUBY-ON-RAILS

어떻게 레일의 특정 작업에 대한 토큰 인증을 무시합니까?

나는에 토큰 인증을 확인하고 싶지 않아하는 특정 동작을 할 때, 어떻게 그것을 확인 건너 레일을 알 수 있습니까?

해결법

  1. ==============================

    1.에서 레일 4 :

    에서 레일 4 :

    skip_before_action :verify_authenticity_token, except: [:create, :update, :destroy]
    

    그리고 3 레일 :

    skip_before_filter :verify_authenticity_token
    

    이전 버전 :

    개별 활동을 위해, 당신은 할 수 있습니다 :

    protect_from_forgery :only => [:update, :destroy, :create]
    #or
    protect_from_forgery :except => [:update, :destroy, :create]
    

    전체 컨트롤러를 들어, 당신은 할 수 있습니다 :

    skip_before_action :verify_authenticity_token
    
  2. ==============================

    2.제외 또는에서만 Rails4에서는 skip_before_action를 사용합니다.

    제외 또는에서만 Rails4에서는 skip_before_action를 사용합니다.

    class UsersController < ApplicationController
      skip_before_action :verify_authenticity_token, only: [:create]
      skip_before_action :some_custom_action, except: [:new]
    
      def new
        # code
      end
    
      def create
        # code
      end
    
      protected
      def some_custom_action
        # code
      end
    end
    
  3. from https://stackoverflow.com/questions/1177863/how-do-i-ignore-the-authenticity-token-for-specific-actions-in-rails by cc-by-sa and MIT license