【问题标题】:Rails view error (on nitrous io IDE) syntax error, unexpected keyword_ensure, expecting end-of-inputRails 视图错误(在 nitrous io IDE 上)语法错误,意外的 keyword_ensure,期望输入结束
【发布时间】:2016-04-12 22:41:39
【问题描述】:

我的代码有问题,我在上面收到这条消息。这是我的代码。我是 ruby​​ 新手

app/views/articles/edit.html.erb

<h>Edit existing article</h>
<%=@article.errors %>
<h2>The following errors prevented the article from getting created</h 2>
<ul>
<%@article.errors.full_messages.each do  |ms g| %>
<li><% ms g %></l i>
<% end %>
</ul>
<% end %>
<%= form_for @article do |f| %>
 <p>
   <%= f.label :title %><b r/>
   <%= f.text_field :title %>
</p>
<p>
  <%= f.label :description %><br/>
  <%= f.text_area :description %>
</p>
<p>
  <%=f.submit %>
<% end %>

【问题讨论】:

  • 请修正标题

标签: ruby-on-rails nitrousio


【解决方案1】:

您似乎有剪切和粘贴问题,或者可能是编辑器问题 - 单词之间有几行中断。

你还有一个额外的 标签,它似乎与任何东西都不匹配

试试这个

<h>Edit existing article</h>
<%=@article.errors %>
<h2>The following errors prevented the article from getting created</h2>
<ul>
  <%@article.errors.full_messages.each do  |msg| %>
    <li><%= msg %></li>
  <% end %>
</ul>
<%= form_for @article do |f| %>
  <p>
  <%= f.label :title %><br/>
  <%= f.text_field :title %>
  </p>
  <p>
  <%= f.label :description %><br/>
  <%= f.text_area :description %>
  </p>
  <p>
  <%=f.submit %>
<% end %>

【讨论】:

  • 小更新,在 你需要 而不是
  • 编辑现有文章

    以下错误导致文章无法创建

【解决方案2】:

你有一堆你可能不想要的空格(包括上面帖子中的文字)。

我认为您的意思是在此部分中将 ms g 设置为 msg

<%@article.errors.full_messages.each do  |msg| %>  # `ms g` => `msg`
  <li><% msg %></li> # `ms g` => `msg`

同时删除&lt;/l i&gt;&lt;b r/&gt;中的空格

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多