I get an error NameError (undefined local variable or method "current_user" for #<APIRouter:0x007ffd54a81f98>):when I try to use current_user to match the restriction . I want some dummy user to be redirected to one set of controllers and other users to route 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)
The restriction of my matches 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 on how I can use the current user in matches? restriction defined in the Rails guide .
Section from routes.rb file:
match '/api/v1/*path', :controller => 'api/v1',
:action => 'handle_create_request',
:via => :post, :constraints => APIRouter.new
: ksol. 3 . request.env["warden"].user(:user)
, APIRouter
def matches? request
user = request.env["warden"].user(:user)
(user && user.is_test) || ENV["USE_RM_APP"] == "true"
end