Rails4.2でcsrf_tokenが表示されない環境があって調べた
<meta name="csrf-token" content="*****************************">
が表示されない環境があって、
「なんで?」
ってなったから調べた話
metaタグ生成場所から追っかける
vendor/bundle/ruby/2.2.0/gems/actionview-4.2.1/lib/action_view/helpers/csrf_helper.rb
にあるこれ
def csrf_meta_tags if protect_against_forgery? [ tag('meta', :name => 'csrf-param', :content => request_forgery_protection_token), tag('meta', :name => 'csrf-token', :content => form_authenticity_token) ].join("\n").html_safe end end
protect_against_forgery はどこで設定されているかというと、これ
vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_controller/metal/request_forgery_protection.rb
# Checks if the controller allows forgery protection. def protect_against_forgery? allow_forgery_protection end
からの
# Controls whether request forgery protection is turned on or not. Turned off by default only in test mode. config_accessor :allow_forgery_protection self.allow_forgery_protection = true if allow_forgery_protection.nil?
その設定が、ここだった!!!
config/environments/test.rb
# Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false