Ruby-on-rails Rails if 语句语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6706035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails if statement syntax
提问by cjm2671
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?
我编写了以下 ERB,但在问号处出现语法错误。来自设计的这个辅助函数当前评估为假。我错过了什么?
<%= if user_signed_in? %>
<%= render 'form' %>
<%= end %>
回答by SteenhouwerD
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.
如果你做 <%= ... %>,它会尝试输出你放在标签之间的东西。但是,如果您执行 <% ... %>,则不会处理任何输出,只会评估代码。如果这不起作用,那么您的 user_signed_in 可能有问题?辅助方法。
回答by Mario Uher
<%=will try to output your user_signed_in?helper, so try:
<%=将尝试输出您的user_signed_in?助手,因此请尝试:
<% if user_signed_in? %>
<%= render 'form' %>
<% end %>
or even better (and less confusing):
甚至更好(并且不那么令人困惑):
<%= render 'form' if user_signed_in? %>
回答by Mahesh
try this
尝试这个
<% if user_signed_in? %>
<%= render 'form' %>
<% end %>

