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 %>
Ruby if...else Statement Notice Ruby uses elsif, not else if nor elif. Executes code if the conditional is true. If the conditional is not true, code specified in the else clause is executed. An if expression's conditional is separated from code by the reserved word then, a newline, or a semicolon.
In if statement, the block executes once the given condition is true, however in unless statement, the block of code executes once the given condition is false.
Ruby conditional statements. Conditional statements are also known by the name of conditional processing or conditional expressions. They are used to perform a certain set of instructions if a specified condition is met. The conditions are generally of Boolean type and return either true or false as the result.
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.
<%=
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? %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With