0

我有设计和用户控制器

路线.rb

  devise_for :users
  
  resources :users do
    resources :blogs
  end

users_controller.rb

class UsersController < ApplicationController
  respond_to :html, :xml, :json

  def create
    @user = User.create(params[:user])
  end

  def show
    @user = User.find(params[:id])
    @asset = Asset.find(params[:id])
    respond_with [@user, @asset]
  end

  def update
    @user = User.find(params[:id])
    @user.update_attributes(params[:user])
    respond_with @user
  end
end

当我访问http://localhost:3000/users/sign_out

我明白了

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User with id=sign_out

更新:

                   users GET    /users(.:format)                                   users#index
                         POST   /users(.:format)                                   users#create
                new_user GET    /users/new(.:format)                               users#new
               edit_user GET    /users/:id/edit(.:format)                          users#edit
                    user GET    /users/:id(.:format)                               users#show
                         PUT    /users/:id(.:format)                               users#update
                         DELETE /users/:id(.:format)                               users#destroy
        new_user_session GET    /users/sign_in(.:format)                           devise/sessions#new
            user_session POST   /users/sign_in(.:format)                           devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                          devise/sessions#destroy
           user_password POST   /users/password(.:format)                          devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                      devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                     devise/passwords#edit
                         PUT    /users/password(.:format)                          devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                            devise/registrations#cancel
       user_registration POST   /users(.:format)                                   devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                           devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                              devise/registrations#edit
                         PUT    /users(.:format)                                   devise/registrations#update
                         DELETE /users(.:format)                                   devise/registrations#destroy

有什么解决办法吗?

4

2 回答 2

4

发生这种情况是因为您的会话被 DELETE 方法破坏了。

从你的rake routes

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

当你访问时http://localhost:3000/users/sign_out,你使用 GET

您可以更改中的方法initializers/devise.rb。刚刚设置config.sign_out_via:get

于 2012-04-29T01:11:46.943 回答
0

您的 routes.rb 文件和您生成的路线似乎不匹配。按顺序评估路线,并提供第一个匹配的路线。

在自定义用户路线之前,您需要设计路线。像这样的东西...

        new_user_session GET    /users/sign_in(.:format)                           devise/sessions#new
            user_session POST   /users/sign_in(.:format)                           devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                          devise/sessions#destroy
           user_password POST   /users/password(.:format)                          devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                      devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                     devise/passwords#edit
                         PUT    /users/password(.:format)                          devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                            devise/registrations#cancel
       user_registration POST   /users(.:format)                                   devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                           devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                              devise/registrations#edit
                         PUT    /users(.:format)                                   devise/registrations#update
                         DELETE /users(.:format)                                   devise/registrations#destroy
                   users GET    /users(.:format)                                   users#index
                         POST   /users(.:format)                                   users#create
                new_user GET    /users/new(.:format)                               users#new
               edit_user GET    /users/:id/edit(.:format)                          users#edit
                    user GET    /users/:id(.:format)                               users#show
                         PUT    /users/:id(.:format)                               users#update
                         DELETE /users/:id(.:format)                               users#destroy

我会确认您的路线文件看起来像您发布的内容,因为它似乎不一致。

于 2012-04-27T16:39:36.247 回答