Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my application_controller.rb I have a line

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

But I get this error on that line

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

Which seems like something to do with devise. But when I do include Devise::TestHelpers, I get env is not defined or something, which doesn't seem like a good solution in any way possible.

Any ideas on how to solve this without needing me to catch errors or regexp to split the path?

share|improve this question

1 Answer 1

This issue may be due to route path which is written in routes by default as and when the application loads first, so join the string to the url you get from request.referrer.

ie, url = request.referrer + "controller_name"

 previousPath = Rails.application.routes.recognize_path(url)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.