设计sign_out路径不工作Rails 4.1

时间:2014-10-02 22:34:57

标签: ruby-on-rails devise

我正在尝试使用设计路径/ user / sign_out,但它会将我带到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

这是我的路线:

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

在我的路由中,我搞砸了什么?还是别的什么?

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

退出路径和链接:

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

= link_to "Sign out", destroy_user_session_path

1 个答案:

答案 0 :(得分:2)

您的注册链接应如下所示<%= link_to 'Logout', destroy_user_session_path, method: :delete %>