Hello i was wondering is there was any way of using an IF statement in a .rhtml..? So far i have this: <div class=''bar2'' id=''barpo6''><strong>State: </strong><%= if @boards.running == "1" render :text => "Running" %></div> What i want to do is to evaluate a column''s value and depending on its value render a text. On the line above i want to render Running if @boards.running is == 1 else render Waiting...? Can i do that the way i looking at it..? Any ideas... Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can embed any ruby code in RHTML - that is what the R stands for - by putting the code in between <% %> or <%=%> Try this: <div class=''bar2'' id=''barpo6''><strong>State: </strong> <%if @boards.running == "1" %> <%= render :text => "Running" %> <%else%> <%= render :text => "Waiting" %> <%end%> </div> you might be able to embed the whole code block in a <%=%> - give it a try. On Jan 24, 10:10 am, Ro Vent <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello i was wondering is there was any way of using an IF statement in a > .rhtml..? > > So far i have this: > <div class=''bar2'' id=''barpo6''><strong>State: </strong><%= if > @boards.running == "1" render :text => "Running" %></div> > > What i want to do is to evaluate a column''s value and depending on its > value render a text. On the line above i want to render Running if > @boards.running is == 1 else render Waiting...? > > Can i do that the way i looking at it..? > > Any ideas... > > Thanks > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hummm.. That didnt work... It didnt give me any errors, but the test wont show up... here is what i have: <div class=''bar2'' id=''barpo6''><strong>State: </strong> <% if @boards.running == "1" %> <%= render :text => "Running" %> <% else %> <%= render :text => "Waiting" %> <% end %> </div> I also tried: <div class=''bar2'' id=''barpo6''><strong>State: </strong><%= render :action => ''state'' %> and in the controller i have def state bstate = Boards.find(@params["id"]) if bstate.running == "1" render :text => "Running" else render :text => "Waiting" end end None of them worked, yet it didnt give me any errors... Any ideas...? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Hello i was wondering is there was any way of using an IF statement in a > .rhtml..? > > So far i have this: > <div class=''bar2'' id=''barpo6''><strong>State: </strong><%= if > @boards.running == "1" render :text => "Running" %></div><...> <%= @boards.running==1?''Running'':''Waiting'' %> Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rimantas Liubertas wrote:> > > <%= @boards.running==1?''Running'':''Waiting'' %> > > Regards, > Rimantas > -- > http://rimantas.com/Cool, thanks... But on my previous post i did the same thing, you just made it more elegant why woudnt it work...? <div class=''bar2'' id=''barpo6''><strong>State: </strong> <% if @boards.running == "1" %> <%= render :text => "Running" %> <% else %> <%= render :text => "Waiting" %> <% end %> </div> It is basically the same thing... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ro Vent wrote:> <div class=''bar2'' id=''barpo6''><strong>State: </strong> > <% if @boards.running == "1" %> > <%= render :text => "Running" %> > <% else %> > <%= render :text => "Waiting" %> > <% end %> > </div>The excess %><% freak me out. <%= render :text => if @boards.running == "1" "Running" else "Waiting" end %> Idiomatic but legible! -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 25, 2007, at 11:26 AM, Ro Vent wrote:> Rimantas Liubertas wrote: >> >> >> <%= @boards.running==1?''Running'':''Waiting'' %> >> >> Regards, >> Rimantas >> -- >> http://rimantas.com/ > > Cool, thanks... But on my previous post i did the same thing, you > just > made it more elegant why woudnt it work...? > > <div class=''bar2'' id=''barpo6''><strong>State: </strong> > <% if @boards.running == "1" %> > <%= render :text => "Running" %> > <% else %> > <%= render :text => "Waiting" %> > <% end %> > </div> > > It is basically the same thing...>> 1=="1" => false Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> >> 1=="1" > => falseThat''s one thing. Second: you shouldn''t use render :text in .rhtml templates. I does not work there (AFAIK). Regards, Rimantas -- http://rimantas.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---