---
title: "rails devise Completed 401 Unauthorized && can't verify csrf token authenticity"
author: "flowerwrong"
date: "2014-11-05T11:34:23Z"
tags: []
categories: ["编程语言"]
slug: "rails-devise-completed-401-unauthorized-can-t-verify-csrf-token-authenticity"
draft: false
lastmod: "2014-11-05T20:17:58Z"
id: 2152540
url: "https://flowerwrong.iteye.com/blog/2152540"
---

最近做项目的时候,由于时间紧,做得太快,没注意细节,导致一些错误.

11.05更新: 偶尔又会出现问题,清理历史记录后就好了!!!

 

1.can't verify csrf token authenticity

google了很久之后通过

```
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  # protect_from_forgery with: :exception
  protect_from_forgery with: :null_session # with: :exception 改为 with: :null_session

  before_action :authenticate_user!
end
```

 

2.这样解决后,又遇到Completed 401 Unauthorized, 情景就是登陆后又调到登陆页面

```
        <p class="notice"><%= notice %></p>

        <p class="alert"><%= alert %></p>
        <% flash.each do |name, msg| %>
            <%= content_tag :div, msg, class: "alert alert-info" %>
        <% end %>
```

 这里就是所有的问题所在

```
        <% flash.each do |name, msg| %>
            <%= content_tag :div, msg, class: "notice alert alert-info" %>
        <% end %>
```