rvent
January 24, 2007, 7:10pm
#1
Hello i was wondering is there was any way of using an IF statement in a
.rhtml…?
So far i have this:
State: <%= if
@boards.running == "1" render :text => "Running" %>
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
rvent
January 24, 2007, 8:29pm
#2
You can embed any ruby code in RHTML - that is what the R stands for -
by putting the code in between <% %> or <%=%>
Try this:
State:
<%if @boards.running == "1" %>
<%= render :text => "Running" %>
<%else%>
<%= render :text => "Waiting" %>
<%end%>
you might be able to embed the whole code block in a <%=%> - give it a
try.
rvent
January 24, 2007, 10:40pm
#3
Hummm… That didnt work… It didnt give me any errors, but the test
wont show up…
here is what i have:
State:
<% if @boards.running == “1” %>
<%= render :text => “Running” %>
<% else %>
<%= render :text => “Waiting” %>
<% end %>
I also tried:
State: <%= 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
rvent
January 25, 2007, 3:29am
#4
Hello i was wondering is there was any way of using an IF statement in a
.rhtml…?
So far i have this:
State: <%= if
@boards.running == "1" render :text => "Running" %>
<…>
<%= @boards.running==1?‘Running’:‘Waiting’ %>
Regards,
Rimantas
http://rimantas.com/
rvent
January 25, 2007, 5:36pm
#5
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!!
rvent
January 25, 2007, 5:47pm
#6
On Jan 25, 2007, at 11:26 AM, Ro Vent wrote:
Cool, thanks… But on my previous post i did the same thing, you
It is basically the same thing…
1==“1”
=> false
Rob B. http://agileconsultingllc.com
[email protected]
rvent
January 25, 2007, 5:59pm
#7
1==“1”
=> false
That’s one thing. Second: you shouldn’t use render :text in .rhtml
templates. I does not work there (AFAIK).
Regards,
Rimantas
http://rimantas.com/
rvent
January 25, 2007, 5:26pm
#8
Rimantas L. 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…