I would like to have the if condition logic like:
var == 10 ? “10″ : “Not 10″
on Rails VIEW. What I tried is following:
<%= session[:id]=="out"? link_to "Sign in", login_path : link_to "Sign out", logout_path%>
I know it looks odd, and unsurprisingly it does not work. So, if I would like to use ternary if condition on VIEW, what is the correct way to do in my case?
———One more condition———
I would like to have two “link_to” in else condition
—–The error message I got——–
compile error
syntax error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
...ession[:id]=="out" ? link_to "Sign in",
Try this (the only diffrence is a space between
"and?and the use of parentheses)Altough parentheses are optional in Ruby they are needed to maintain operator precedence in some cases.
IMHO ternary operators are hard to read. You could also do something more verbose: