0

I want to check the value of env[:clearance] to see why something is broken.

How can I do this. I tried puts:

  config.user.current = Proc.new { env[:clearance].current_user }
  puts "ENV[:CLEARANCE]: #{env[:clearance]}"

but that gets: undefined local variable or methodenv' for main:Object (NameError)`

How can I get some visibility into the env hash in this situation? BTW this is loosely related to the Clearance gem.

Meltemi
  • 37,979
  • 50
  • 195
  • 293
  • 1
    Shouldn't it be `ENV[:clearance]` instead of `env[:clearance]` ? – Arup Rakshit Mar 24 '15 at 19:35
  • perhaps but that doesn't seem to work either. following [their advice](https://github.com/thoughtbot/clearance/#integrating-with-rack-applications). – Meltemi Mar 24 '15 at 19:40
  • I think `env` is a helper method, which you can't access before *initializer* is loaded and you are trying to access it inside [initializer](https://github.com/thoughtbot/clearance/#configure) only.. – Arup Rakshit Mar 24 '15 at 19:50
  • well, fwiw, I'm trying to access `env` in a Proc inside another initializer (not the initializer for Clearance, itself) – Meltemi Mar 24 '15 at 20:05
  • because it's a Proc maybe it can't be debugged easily?!? – Meltemi Mar 24 '15 at 20:09
  • Well, try this simple Ruby code - `p = Proc.new { x } x = 10 p.call` and see what it throws. – Arup Rakshit Mar 24 '15 at 20:24

1 Answers1

0

It's not clear what problem you are trying to solve or what config.user.current is (it's not Clearance). One problem however is that you are trying to use the method env in the proc where it will not be defined. The proc has its own scope.

If you just want to see what ENV is after the clearance middleware has run the simplest thing to do would be to put a binding.pry or debugger statement inside a controller and access env that way.

The clearance environment is set by middleware in response to a request. It will not be set in an initializer.

Derek Prior
  • 3,497
  • 1
  • 25
  • 30