【问题标题】:Rails.application.routes.recognize_path error with undefined method authenticateRails.application.routes.recognize_path 错误与未定义的方法验证
【发布时间】:2013-09-02 18:29:06
【问题描述】:

在我的 application_controller.rb 中有一行

# Get the previous url string nicely.
previousPath = Rails.application.routes.recognize_path(request.referrer)

但是我在那一行得到了这个错误

NoMethodError (undefined method `authenticate?' for nil:NilClass)

这似乎与设计有关。 但是当我确实包含 Devise::TestHelpers 时,我得到 env is not defined 之类的,这似乎不是一个好的解决方案。

关于如何在不需要我捕获错误或正则表达式来拆分路径的情况下解决此问题的任何想法?

【问题讨论】:

    标签: ruby-on-rails authentication devise nomethoderror


    【解决方案1】:

    此问题可能是由于在应用程序首次加载时默认写入路由的路径路径,因此请将字符串加入从 request.referrer 获得的 url。

    即,url = request.referrer + "controller_name"

     previousPath = Rails.application.routes.recognize_path(url)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 2014-04-10
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多