我试图检查一个条件,然后包括“停止服务器”和“启动服务器”锚标签。我有个错误。
请告诉我要换什么。谢谢。

<%= condition ? "Running" <a href='/stop'> Stop Server </a> :"Stopped" <a href='/start'> Start Server</a> %> </td>

最佳答案

你把代码和HTML混在一起了。这样做会更清楚:

<% if condition %>
    "Running" <a href='/stop'> Stop Server </a>
<% else %>
    "Stopped" <a href='/start'> Start Server</a>
<% end %>

关于ruby-on-rails - 带有html标记的erb中的Ruby三元运算符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21029942/

10-13 02:11