2009-07-24 2 views
150

확실한 토큰을 확인하고 싶지 않은 특정 동작이있을 경우 레일스 검사를 건너 뛰도록 지시하려면 어떻게해야합니까?Rails의 특정 작업에 대한 인증 토큰은 어떻게 무시합니까?

개인의 행동에 대한
+6

+1, 슬프게도 자신의 질문에 답할 때 슬프게도 싫증을 내었습니다.이 질문은 완벽하게 합법적입니다. –

+15

어. 나는 그것을 위해 모든 것을 검색하고 대답을 찾기가 어려웠 기 때문에 여기에 넣었습니다. 다른 사람들에게 도움이 될 것이라고 생각했습니다. 투표 해 주셔서 감사합니다. – edebill

답변

201

, 당신이 할 수 있습니다

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

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

skip_before_action :verify_authenticity_token 

그리고 레일 3.X이 필요합니다

skip_before_filter :verify_authenticity_token 
+0

thx 특정 컨트롤러 및 특정 작업에 대해 – clyfe

+0

을 문서화하려면 skip_before_filter : verify_authenticity_token, : only :> : my_unprotected_action을 사용하십시오. 나는 여기에 대한 답을 찾기 위해왔다 : 이것은 끔찍한 생각인가? 아약스 응답이 내 세션을 먹기 때문에이 작업을 수행하려고합니다. – Danny

+29

레일 4의 경우 'skip_before_action : verify_authenticity_token'을 사용하십시오. [API 문서] (http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html) – amoebe

23

에서 레일 4skip_before_actionexcept 또는 01을 사용합니다..

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 
관련 문제