Hi everyone,
This seems so basic, and yet I can’t quite figure it out.
Say I have some code in an .rhtml document:
<%=
if @session[:user_id]
link_to somethingA
else
link_to somethingB
link_to somethingC
end
-%>
Only the link to somethingC will show in the second case. I understand
that the last thing returned from that else block is that last line. In
php i could just add a ‘print’ in front of both calls to link_to to get
the text to the browser. How can I do this here without just wrapping
every line in multiple <%= %>?
Thanks!
Jack
jack dempsey wrote:
Hi everyone,
This seems so basic, and yet I can’t quite figure it out.
Say I have some code in an .rhtml document:
<%=
if @session[:user_id]
link_to somethingA
else
link_to somethingB
link_to somethingC
end
-%>
How 'bout:
<%=
if @session[:user_id]
link_to somethingA
else
link_to( somethingB ) + link_to( somethingC )
end
-%>
Whammo!
–
Matthew B. :: [email protected]
Resume & Portfolio @ http://madhatted.com
Only the link to somethingC will show in the second case. I understand
that the last thing returned from that else block is that last line. In
php i could just add a ‘print’ in front of both calls to link_to to get
the text to the browser. How can I do this here without just wrapping
every line in multiple <%= %>?
Thanks!
Jack
Hi Matt,
Yeah, I did that, but as a matter of principal, I feel like there should
be a different way 
Ok, thanks!
Jack
Matthew B. wrote:
jack dempsey wrote:
Hi everyone,
This seems so basic, and yet I can’t quite figure it out.
Say I have some code in an .rhtml document:
<%=
if @session[:user_id]
link_to somethingA
else
link_to somethingB
link_to somethingC
end
-%>
How 'bout:
<%=
if @session[:user_id]
link_to somethingA
else
link_to( somethingB ) + link_to( somethingC )
end
-%>
Whammo!
–
Matthew B. :: [email protected]
Resume & Portfolio @ http://madhatted.com
Only the link to somethingC will show in the second case. I understand
that the last thing returned from that else block is that last line. In
php i could just add a ‘print’ in front of both calls to link_to to get
the text to the browser. How can I do this here without just wrapping
every line in multiple <%= %>?
Thanks!
Jack
How about something like this?
<%= session[:user_id].nil? ? link_to(“B”, :action => “somethingB”) <<
link_to(“C”, :action => “somethingC”) : link_to(“A”, :action =>
“somethingA”) -%>