Rails if语句语法 [英] Rails if statement syntax

查看:52
本文介绍了Rails if语句语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下ERB,并在问号处出现语法错误.来自devise的此辅助函数当前评估为false.我错过了什么?

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 %>

推荐答案

尝试一下:

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

如果您执行<%= ...%>,它将尝试输出放置在标签之间的内容.但是,如果您执行<%...%>,则不处理任何输出,仅对代码进行评估.如果这不起作用,那么您的user_signed_in可能有问题吗?辅助方法.

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.

这篇关于Rails if语句语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆