grigio
grigio

Reputation: 167

Why this code works differently in Heroku?

I use this code to set a value in a view even if current_user doesn't exist. If you know a better way suggest an alternative bc many method I use raise an exception otherwise.

def setval_if(valgood, valbad=nil)
  begin
    return valgood if yield
  rescue
  else
  end
end

setval_if("no exception raised") { true }
# => "no exception raised" # my machine, correct.
# => nil # Heroku

but If I add this dirty hack it works also in heroku

def setval_if(valgood, valbad=nil)
  begin
    return valgood if yield
    puts "suca vaff.."
  rescue
  else
  end
end

setval_if("no exception raised") { true }
# => "no exception raised" # my machine, correct.
# => "no exception raised" # Heroku

why why why???? :D

Upvotes: 0

Views: 81

Answers (1)

bigtunacan
bigtunacan

Reputation: 4986

I believe this is an issue related to the version of Ruby that is being run. I can replicate this same issue on my local machine with rvm under ruby-1.9.2-p320.

I ran the code on Heroku against one of my apps and the error did not occur; that particular app was running on ruby-1.9.3-p194

Can you confirm which Heroku stack you are running on? To do this simply login to heroku, then run the following

heroku stack -a yourappnamehere

I ran the test under the latest heroku stack; cedar.

Upvotes: 1

Related Questions