TuxedoTomson
TuxedoTomson

Reputation: 483

Devise sign_out path not working Rails 4.1

I'm trying to use the devise path /user/sign_out but it's taking me to a user show page with the id sign_out

Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_out"}
Rendered users/show.html.haml within layouts/application (5.0ms)
Completed 500 Internal Server Error in 9ms

This is my routes:

Rails.application.routes.draw do

  devise_for :fans, controllers: { registrations: "fans/devise/registrations"}
  devise_for :users, controllers: { registrations: "users/devise/registrations"}

  devise_scope :fan do
    get '/auth/facebook_fan/callback' => "fans/devise/omniauth_callbacks#facebook"
  end
  devise_scope :artist do
    get '/auth/facebook_artist/callback' => "users/devise/omniauth_callbacks#facebook"
    get '/users/auth/stripe_connect/callback' =>  "users/devise/omniauth_callbacks#stripe_connect"
  end

  resources :about

  resources :rewards, only: :show do 
    resources :pledges, only: [:new, :create, :update]
  end

  resources :users, only: [:show, :index] do
    resources :rewards, only: [:new, :create, :update, :index]
    resources :pledges, only: [:show, :new, :create]
  end
  root "welcome#index"
 end

Where in my routing am I messing things up? Or is it something else?

UsersController:

class UsersController < ApplicationController
  helper_method :user
  respond_to :js

  def index
    respond_to do |format|
      format.html
      format.js
    end
  end

  protected

  def User
    UserPresenter.new(User.find(params[:id]))
  end
end

Registrationscontroller

    class Users::Devise::RegistrationsController < Devise::RegistrationsController
      def update
        # For Rails 4
        account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
        # For Rails 3
        # account_update_params = params[:user]

        # required for settings form to submit when password is left blank
        if account_update_params[:password].blank?
          account_update_params.delete("password")
          account_update_params.delete("password_confirmation")
        end

        @user = User.find(current_user.id)
        if @user.update_attributes(account_update_params)
          set_flash_message :notice, :updated
          # Sign in the user bypassing validation in case their password changed
          sign_in @user, :bypass => true
          redirect_to user_path(@user)
        else
          render "edit"
        end
      end

      def new
        @user = User.new
        respond_to do |format|
          format.html
          format.js
        end
      end
    end

Sign out path and link:

destroy_user_session DELETE /users/sign_out(.:format)                     devise/sessions#destroy

= link_to "Sign out", destroy_user_session_path

Upvotes: 2

Views: 778

Answers (1)

kobaltz
kobaltz

Reputation: 7070

Your signout link should look soemthing like this <%= link_to 'Logout', destroy_user_session_path, method: :delete %>

Upvotes: 3

Related Questions