Answers:
在Rails 4中:
skip_before_action :verify_authenticity_token, except: [:create, :update, :destroy]
和Rails 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
在Rails4您使用skip_before_action
与except
或only
。
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