【问题标题】:rails 4 views form syntax errorrails 4 视图表单语法错误
【发布时间】:2013-10-18 22:22:42
【问题描述】:

Rails 4,红宝石 2.0。 我想创建一个公共文件服务页面,其中包含每个文件的下载链接,并可以使用复选框和“下载检查的文件”按钮检查多个文件的下载。

我在 index.html.erb 中的代码

<% form_tag(controller: "files", action: "download_many", method: "get")%>
<h1>St.Catherines</h1>
  <ul>
<% @stcatherines.each do |file|%>
  <li><%= link_to file, :action => "download", :name =>file %></li>
  <%check_box_tag(file)%>
<%end%>
  <%submit_tag :value => "Download checked files" %>
  </ul>
<%end%>

@stcatherines 是一个字符串数组 下载链接有效,一定是表格有问题。 我遇到了一个奇怪的错误:

  .../app/views/files/index.html.erb:11: 
  syntax error, unexpected keyword_ensure, expecting end-of-input

请注意,语法错误出现在第 11 行,而我只有 10 行代码。

【问题讨论】:

  • 您的提交标签必须是 "下载检查过的文件" %>。另外你 chek_box_tag 必须是 check_box_tag
  • @Raghu:感谢您找到错字。我按照你的建议编辑了我的代码,但我仍然得到完全相同的错误。之后编辑了问题。

标签: forms checkbox ruby-on-rails-4 syntax-error erb


【解决方案1】:

我认为您错过了打开form_tag 并添加了结尾,导致语法错误。在 form_tag 声明之后添加 do 应该可以解决它...尝试将代码更改为以下内容(注意在第 1 行添加了 do):

<% form_tag(controller: "files", action: "download_many", method: "get") do %>
<h1>St.Catherines</h1>
  <ul>
<% @stcatherines.each do |file|%>
  <li><%= link_to file, :action => "download", :name =>file %></li>
  <% check_box_tag(file) %>
<% end # each %>
  <%submit_tag :value => "Download checked files" %>
  </ul>
<% end # form_tag %>

【讨论】:

  • 非常感谢!这行得通。我从 [guides.rubyonrails.org/form_helpers.html] 复制了内容,但没有弄对,sn-ps 只是表单的一部分 :) (我的英语和我的编程能力仍然很烂;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-17
  • 1970-01-01
  • 2017-06-29
  • 1970-01-01
相关资源
最近更新 更多