ede*_*ill 223
在Rails 4中:
skip_before_action :verify_authenticity_token, except: [:create, :update, :destroy]
Run Code Online (Sandbox Code Playgroud)
和Rails 3:
skip_before_filter :verify_authenticity_token
Run Code Online (Sandbox Code Playgroud)
对于以前的版本:
对于个人行为,您可以:
protect_from_forgery :only => [:update, :destroy, :create]
#or
protect_from_forgery :except => [:update, :destroy, :create]
Run Code Online (Sandbox Code Playgroud)
对于整个控制器,您可以:
skip_before_action :verify_authenticity_token
Run Code Online (Sandbox Code Playgroud)
Epi*_*ene 27
在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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67397 次 |
| 最近记录: |