【问题标题】:Rails js.erb executing within if statement that is falseRails js.erb 在 if 语句中执行是错误的
【发布时间】:2016-06-15 16:45:18
【问题描述】:

animal.js.erb

<% if @animal.type == "Cat" %>

    <% if @animal.meow == "Loud" %>
        alert("Loud Cat");
    <% else %>
        alert("Quiet Cat");
    <% end %>

<% else %>

    <% if @animal.bark == "Ferocious" %>
        alert("Ferocious Dog");
    <% else %>
        alert("Nice Dog");
    <% end %>
<% end %>

@animal.type == "Dog" 我仍然收到@animal.meow 方法不存在的错误。

为什么会读取 if 语句并出错?

似乎.erb 正在执行if @animal.meow 语句,即使@animal.type is "Dog" 也是如此

【问题讨论】:

  • 让我们看看你的动物模型,还有&lt;% if @animal.meow == "Loud %&gt;&lt;% if @animal.bark == "Ferocious %&gt; 都缺少结束双引号
  • 抱歉,帖子输入错误

标签: javascript ruby-on-rails ruby-on-rails-4 erb


【解决方案1】:

您忘记在&lt;% if @animal.meow == "Loud %&gt;&lt;% if @animal.bark == "Ferocious %&gt; 中添加结束引号

【讨论】:

  • 抱歉,发布的问题是错字,而不是问题本身
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 2022-01-25
  • 1970-01-01
相关资源
最近更新 更多