I have a case statement and I am trying to use the ternary operator to do additional conditional checking. But it errors out.
here is a sample of the code
case url
when partner_x_url then Rails.env.development? ? partner_signup_url : partner_signup_url :protocol => "https"
.
.
.
else regular_signup_url
end
The really weird thing is that it works if use the following
case url
when partner_x_url then if Rails.env.development?; partner_signup_url; else partner_signup_url :protocol => "https"; end
.
.
.
else regular_signup
end
Any ideas of why this is happening?
You’re missing the
?operator:Happens to me all the time with a method ending in a question mark 🙂
EDIT: Since you now added that operator, I suspect it has to do with operator precedence. Try to avoid those kind of issues with using parentheses around function arguments:
Example: Without function parentheses, you get a syntax error:
With parentheses, you don’t: