In a controller action, I need to check whether the controller is being accessed by the application itself (which would set a session variable current_user), or from an api call. The beginning of my controller looks like this:
130: def create
131: # handle the possibility that this is an api call
132: api_call = current_user.nil?
=> 133: binding.pry
When I pry in to see what is going on, I get this nonsensical output:
[1] pry(#<Crm::ConnectionsController>)> api_call
=> false
[2] pry(#<Crm::ConnectionsController>)> current_user
=> nil
[3] pry(#<Crm::ConnectionsController>)> current_user.nil?
=> true
[4] pry(#<Crm::ConnectionsController>)> api_call = current_user.nil?
=> true
[5] pry(#<Crm::ConnectionsController>)> api_call
=> true
And when I change the variable api_call from the pry console with the following line, then resume execution, the controller behaves from there on as if api_call is set to true.
Why would this be? Why is my controller not setting api_call correctly in the first place?