ruby-on-rails - 错误 : "unexpected keyword else, expected keyword end"?

标签 ruby-on-rails ruby embedded-ruby

我正在学习 Rails,但在以下代码中出现语法错误 unexpected keyword else, expected keyword end,我不知道为什么。

<% if @quo.pro_con.nil? do %>
  <div class="procon">
    <%= f.label :pro_con %><br>
    <%= f.check_box :pro_con %>
  </div>
  <div class="comment">
    <%= f.label :comment %><br>
    <%= f.text_area :comment %>
  </div>
<% else %> 
  <p>
    <strong>Pro Con:</strong>
    <%= @quo.pro_con %>
  </p>
  <p>
    <strong>Comment:</strong>
    <%= @quo.comment %>
  </p>
<% end %> 

为什么我会收到错误消息,unexpected keyword else, expected keyword end

最佳答案

if 不需要 do 子句。解释器看到 do 并等待 end 匹配。将第一行更改为:

<% if @quo.pro_con.nil? %>

关于ruby-on-rails - 错误 : "unexpected keyword else, expected keyword end"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21498711/

相关文章:

ruby-on-rails - 在 ruby​​ 代码中更新思维 sphinx 索引

javascript - Fullcalendar 仅在页面重新加载后出现

ruby-on-rails - 如何在 Rails 中每隔几秒运行一些 Action 10 分钟?

Ruby 语法问题 : Rational(a, b) 和 Rational.new!(a, b)

CSS 代码在 Chrome 和 Firefox 中呈现不同的结果

html - 如何改变这些 f.inputs?

javascript - 有没有办法在 my/public/javascripts 目录中的 javascript 文件中执行嵌入式 ruby​​?

ruby-on-rails - 为什么 `button tag` 不会显示对话框进行确认?

javascript - bootstrap.js 文件 - 这些是服务器端包含的独特类型吗?这些文件应该如何实现?

ruby-on-rails - accepts_nested_attributes_for 对于 has_one 关系不能正常工作