title: Rails 4 + Devise + AJAX: Completed 401 Unauthorized
body: <p>I have a subclass of the devise sessions controller:</p>
  
  <pre><code>class SessionsController &lt; Devise::SessionsController
    respond_to :html, :js
  
    def create
      login_process do
        super
      end
    end
  
    private
  
      def login_process
        if !anonymous_user?
          old_user = guest_user
        end
        yield
        if user_signed_in?
          current_user.cart.replace_cart_items!(old_user.cart.cart_items) unless old_user.cart.cart_items.empty?
        end
      end
  
  end 
  </code></pre>
  
  <p>And the form that I pasted from their site for having customized sign in forms on other pages: <a href="https://github.com/plataformatec/devise/wiki/How-To%3a-Display-a-custom-sign_in-form-anywhere-in-your-app" rel="nofollow">https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app</a></p>
  
  <pre><code>    &lt;div class="log_in_div"&gt;
          &lt;h3&gt;Log in&lt;/h3&gt;
          &lt;%= form_tag session_path(:user), remote: true do %&gt;
              &lt;div&gt;
                  &lt;%= label_tag 'user[email]', 'Email' %&gt;
                &lt;%= text_field_tag 'user[email]' %&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;%= label_tag "user[password]", "Password" %&gt;
                &lt;%= password_field_tag 'user[password]' %&gt;
              &lt;/div&gt;
  
            &lt;%= check_box_tag 'user[remember_me]' %&gt;
            &lt;%= label_tag 'user[remember_me]', 'Remember me' %&gt;&lt;br&gt;
            &lt;%= submit_tag "Log in" %&gt;
            &lt;%= link_to "Forgot your password?", new_password_path(:user) %&gt;
          &lt;% end %&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>However, when I submit the form through the browser, I get this:</p>
  
  <pre><code>    Processing by SessionsController#create as JS
        Parameters: {"utf8"=&gt;"✓", "user"=&gt;{"email"=&gt;"gfdgdgd", "password"=&gt;"[FILTERED]"}, "commit"=&gt;"Log in"}
      Completed 401 Unauthorized in 3ms
  </code></pre>
  
  <p>Does anyone know what's going on?</p>