Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats wrong with my simple If Else?

Im new to RoR/Ruby and i cant seem to get the simplest thing to work. (trust me, ive search google and reread docs, i dont know what wrong)

So in my main view, I added the following:

<%= if 1>2 %>
  <%=     print "helllloooo" %>
<%= else %>
  <%= print "nada" %>
<%= end %>

And nothing is outputted..

**UPDATE**

Ok heres my new CORRECTED code and its STILL NOT WORKING

<th>
  <% if 1 > 2 %>
    <%= print "helllloooo" %>
  <% else %>
    <%= print "nada" %>
  <% end %>  
</th>
like image 915
Jonah Katz Avatar asked Aug 03 '11 20:08

Jonah Katz


2 Answers

Your statements are not intended to be displayed so instead of

<%= if 1>2 %>

write

<% if 1 > 2 %>

Same thing for else and end


EDIT

<% if 1 > 2 %>
<%= "helllloooo" %>  #option 1 to display dynamic data
<% else %>
nada                 #option 2 to display static data
<% end %>
like image 164
apneadiving Avatar answered Oct 30 '22 10:10

apneadiving


You don't need to use print, or even ERB for the text. Also, your if, else, and end statements should be <%, not <%=:

<% if 1 > 2 %>
helllloooo
<% else %>
nada
<% end %>
like image 45
Dylan Markow Avatar answered Oct 30 '22 09:10

Dylan Markow