【问题标题】:Mongoid::Errors::DocumentNotFound in UsersController#show用户控制器中的 Mongoid::Errors::DocumentNotFound#show
【发布时间】:2013-12-19 06:53:17
【问题描述】:

每当我尝试在使用 mongoid rails 4.0.1 并设计的应用程序中单击注销时,我都会在 UsersController#show 中收到错误 Mongoid::Errors::DocumentNotFound。

我的用户控制器代码是

class UsersController < ApplicationController
  before_filter :authenticate_user!

  def index

    @users = User.all
  end

  def show

    @user = User.find(params[:id])
  end

end

错误是:

问题:未找到 ID 为 sign_out 的类用户的文档。总结:当使用 id 或 id 数组调用 User.find 时,每个参数必须匹配数据库中的文档,否则将引发此错误。搜索的是 id(s):sign_out ...(共 1 个),但未找到以下 id:sign_out。解决方法:搜索数据库中的一个id或者将Mongoid.raise_not_found_error配置选项设置为false,这会导致在搜索单个id时返回nil而不是引发这个错误,或者在搜索时只抛出匹配的文档倍数。

请帮助我解决这个问题。

【问题讨论】:

    标签: mongodb devise ruby-on-rails-4 mongoid


    【解决方案1】:

    一个类似的问题,是here

    虽然所有第一个答案都很重要并且需要检查(确保您的“退出”链接上有:method =&gt; :delete),但这是为我的 Rails 4.1.6 + Mongoid 应用程序修复它的第三个答案:添加 jquery_ujs。

    具体来说,将 //= require jquery_ujs 添加到我的 application.js 文件中,我的链接断开并成功退出。

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      相关资源
      最近更新 更多