Home undefined local variable or method 'request' - in controller helper
Reply: 0

undefined local variable or method 'request' - in controller helper

user9263 Published in September 20, 2018, 12:43 pm

We have been seeing an increasing number of errors with the same call sight:

NameError: undefined local variable or method 'request' for :false:Symbol

They are all raising from an authentication helper located in lib. This method runs successfully 99% of the time (we know because it logs you in without issue). However, for a very small number of requests the request object can't be found, as shown in the error message.

We have been seeing this for a variety of user agents. For what it's worth, ApplicationController includes (via include) the helper in question.

Is there any common debugging techniques or known issues where request can be missing during a Rails request? If it helps, the same occurs for cookies.

The relevant bits of code:

# lib/authenticated_system.rb
module AuthenticatedSystem
  def logged_in?
    current_user != :false

  def current_user
    @current_user ||= login_via_cookie || login_via_url || :false

  def login_via_cookie
    Rails.logger.info "IP: #{request.ip}" # example of accessing request
    if token = cookies[:web_token]
      User.find_by(auth_token: token)

  def login_via_url
    # return User or nil

# app/controllers//foo_controller.rb
class FooController < ApplicationController
  include Alerting

  def show

# lib/alerting.rb
module Alerting
  def log_alert(user)
    Rails.logger.info "User: #{user.id}" # example of accessing user
share|improve this question
  • Note that it's trying to run the method request on a symbol... so some method that was to return an object that responds to request instead is returning :false. Check the code for a call like xxx.request and then examine the xxx method to see under what circumstances it would return :false – SteveTurczyn Feb 12 at 13:26
  • Can you post, how calling lib library any async calls or jobs ? – 7urkm3n Feb 12 at 13:58
  • Do you have any background jobs that use the method that calls the request or the cookies method? – Tobias Feb 12 at 14:07
  • @SteveTurczyn I've added the relevant code. I'm not setting request to anything, or self, but I do mention :false in some of the code. Perhaps that isn't behaving the way I'm expecting it should? – Joe Masilotti Feb 13 at 10:26

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.349581 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO