35

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 %>
1
  • 1
    Note that '?' and '!' are valid characters in method names. Commented Jul 15, 2011 at 11:14

3 Answers 3

87

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.

Sign up to request clarification or add additional context in comments.

Comments

27

<%= will try to output your user_signed_in? helper, so try:

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

or even better (and less confusing):

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

1 Comment

Thanks for describing the difference between <%= and <%
2

try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.