John Servinis John Servinis - 1 year ago 80
Ruby Question

Performing operations on heroku ENV vars in rails

I'm trying to test for equality against a heroku ENV var, to no avail.


if a['answer']['question_id'] == ENV['HEROKU_VAR']
# this expression was supposed to be true!

I've sent each side of the expression to the debugger and they print the same value.

My only presumption is that the ENV var is an object that can't have operations performed on it.

Anyone know what I could be doing wrong?

Answer Source

Indeed, even if you declare your Heroku var as an int, e.g. HEROKU_VAR=12345, when you call it from anywhere in your app, it seems it throws back a string, which you need to convert back to an integer. I solved this problem as follows:

if a['answer']['question_id'] == ENV['HEROKU_VAR'].to_i
  # this expression was supposed to be true and it IS!