Rails if statement syntax

后端 未结 3 975
心在旅途
心在旅途 2021-01-03 17:56

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?

<
相关标签:
3条回答
  • 2021-01-03 18:37

    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.

    0 讨论(0)
  • 2021-01-03 18:46

    <%= 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? %>
    
    0 讨论(0)
  • 2021-01-03 18:54

    try this

    <% if user_signed_in? %>
        <%= render 'form' %>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题