Rails if statement syntax

cjm2671 picture cjm2671 · Jul 15, 2011 · Viewed 68.7k times · Source

I've written the following ERB and am getting a syntax error at the question mark. This helper function from devise currently evaluates as false. What have I missed?

<%= if user_signed_in? %>
<%= render 'form' %>
<%= end %>

Answer

SteenhouwerD picture SteenhouwerD · Jul 15, 2011

Try this :

<% if user_signed_in? %>
  <%= render 'form' %>
<% end %>

If you do <%= ... %>, it will try to output the thing you put between the tags. But, if you do <% ... %>, then no output is processed, just the code is evaluated. If this is not working, then there is probably something wrong with your user_signed_in? helper method.