-6ren">
gpt4 book ai didi

ruby-on-rails - ruby on rails if 语句在 index.html.erb 页面上带有 bool 值

转载 作者:行者123 更新时间:2023-12-04 00:08:21 25 4
gpt4 key购买 nike

也许我错过了一些简单的东西,但看了一段时间后我无法弄清楚。

我想检查表单上数据库中的 bool 值是否为真,是否显示向上箭头,如果不是向下箭头。

我有这个

<% for probe in @probes %>
<tr id="<%= cycle('list-line-odd', 'list-line-even') %>">
<td>
<%= if probe.online = true %>
<%= image_tag("online-icon.png", :alt => "Online") %>
<%= end %>
</td>
<td><%= link_to probe.probe_name, probe %></td>
</tr>
<% end %>

但它又回来了这个错误

编译错误
syntax error, unexpected ')', expecting kTHEN or ':' or '\n' or ';'

@output_buffer.concat "\t \t"; @output_buffer.concat(( if probe.online = true ).to_s);
@output_buffer.concat "\n"

syntax error, unexpected kEND
@output_buffer.concat " \t \t"; @output_buffer.concat(( end ).to_s);@output_buffer.concat "\n"

箭头指向 .to_s

最佳答案

首先,您使用 == 测试相等性,不是 = ,这是赋值运算符。

其次——这就是错误所提示的——你只需要使用简单的 <%而不是 <%=带有 if 语句。后一种形式试图把里面的代码变成字符串,当然写(if something == true).to_s毫无意义。 — 没有可能的字符串值。

关于ruby-on-rails - ruby on rails if 语句在 index.html.erb 页面上带有 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1201169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com