Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:41+00:00 2026-06-11T21:23:41+00:00

I get an error NameError (undefined local variable or method current_user for #<APIRouter:0x007ffd54a81f98>): when

  • 0

I get an error NameError (undefined local variable or method "current_user" for #<APIRouter:0x007ffd54a81f98>): when I try to use current_user in a matches? constraint. I want certain dummy user to be routed to one set of controllers and other users to be routed to another set of controllers. However, when I try to use current_user I get an error.

  • devise (2.0.4)
  • rails (3.2.2)

My matches constraint is defined in the APIRouter Class:

class APIRouter
  def matches? request
    @use_rm_app = ENV["USE_RM_APP"] == "true" || (current_user && current_user.is_test)
  end
end

Any ideas as to how I can use current user in the matches? constraint as defined in the Rails guide.

Section from the routes.rb file:

#  Route to the rm_app controller if APIRouter says we should, otherwise use the real backend controllers.
match '/api/v1/*path', :controller => 'api/v1', 
  :action => 'handle_create_request', 
  :via => :post, :constraints => APIRouter.new

UPDATE: Solved thanks to ksol. Attempt 3 works. Get user using request.env["warden"].user(:user)

Solution is to modify the APIRouter

  def matches? request
    user = request.env["warden"].user(:user)
    (user && user.is_test) || ENV["USE_RM_APP"] == "true"
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:23:43+00:00Added an answer on June 11, 2026 at 9:23 pm

    current_user is only available in your controllers and views. There is more than one way to achieve what you want, the easier being supplying it as a parameter to your method.

    EDIT

    if current_user if accessible in the router, you can pass it to your constraints class by doing constraints: APIRouter.new(current_user). Then you need to define APIRouter#initialize and store the current_user in an instance var that you can use in matches?.

    EDIT 2

    I just remembered devise allows you to do this in your router :

    authenticated :user do
      root :to => "main#dashboard"
    end
    

    I don’t know how to ensure that user.is_test though.

    EDIT 3

    Last attempt. request.env["warden"].user(:user) should give you a user if one is authenticated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently if it doesn't exists I get a the undefined local variable or method
I get the following error, when i run my script. fetch_scores.rb:20:in `<main>': undefined local
I use the following jquery statements but i get error in this function onGetDataSuccess(result)
When we try to create a view within a funcion we get ERROR: there
I'm calling a sikuli function, inside Sikuli IDE, but I get this error NameError:
I get the error NameError: global name 'entryWidget' is not defined in the following
In Python 2: raw_input() In Python 3, I get an error: NameError: name 'raw_input'
Does anyone know why I get the following error when I use the web_step#follow
when I try signing up in my local host this is the error I
I just added :confirmable but am now getting an error: NameError in Devise::RegistrationsController#create undefined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.