【发布时间】: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" 也是如此
【问题讨论】:
-
让我们看看你的动物模型,还有
<% if @animal.meow == "Loud %>、<% if @animal.bark == "Ferocious %>都缺少结束双引号 -
抱歉,帖子输入错误
标签: javascript ruby-on-rails ruby-on-rails-4 erb