CRUD를 위해 AJAX를 사용하는 컨트롤러가 있지만, 원격 링크 중 하나를 클릭 할 때마다 (예를 들어 삭제) 레일 서버가 나를 로그 아웃하고 리디렉션하기로 결정했습니다. 서버 로그를 검사하면 CSRF Authenticity를 확인할 수 없다고 나와 있습니다. 내 요청에 CSRF 토큰은 어떻게 포함합니까?개발자가 AJAX 요청시 로깅을 로깅합니다. Rails 3.1
실행 : 는 - 3.1 레일 - JQuery와 레일 1.0.13
관련 컨트롤러 액션 - 1.4.4 고안 :
def destroy
@article = Article.find(params[:id])
if @article.destroy
flash[:notice] = "Article deleted."
respond_to do |format|
format.html{redirect_to articles_path}
format.js{}
end
else
flash[:error] = "Try Again."
redirect_to :back
end
레이아웃/application.html.erb
<head>
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap-1.1.1.min.css>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag :defaults %>
<script type="text/javascript">jQuery.ajaxSetup({ beforeSend: function (xhr) { xhr.setRequestHeader("Accept", "text/javascript"); } });</script>
<%= csrf_meta_tag %>
<%= yield(:head) %>
</head>
을
미리 감사드립니다.
아, 이것도 내 문제를 해결했습니다. 감사! – neezer