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 -- Posted via http://www.ruby-forum.com/.
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 Beale :: mixonic@synitech.com 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-- Posted via http://www.ruby-forum.com/.
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 Beale 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 Beale :: mixonic@synitech.com > 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-- Posted via http://www.ruby-forum.com/.
How about something like this? <%= session[:user_id].nil? ? link_to("B", :action => "somethingB") << link_to("C", :action => "somethingC") : link_to("A", :action => "somethingA") -%> 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 >-%> >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 > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060818/7a49ddd1/attachment.html