【发布时间】:2015-06-01 13:34:15
【问题描述】:
我正在基于 railsguide 构建一个 rails 应用程序
http://guides.rubyonrails.org/getting_started.html
它在erb中要求的语法是……
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
由于某种原因,这读作
https://localhost:3000/articles/[#]
其中 # 是要删除的给定记录。换句话说,我想删除一条记录,它会将我的代码解释为显示该记录。
我做错了什么?
更多信息
这是动态生成的
<td>
<a rel="nofollow" data-method="delete" href="/articles/2">Destroy</a>
</td>
application.html.erb 有以下...
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
控制器定义
def destroy
@article= Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
与在 application.html.erb 中使用“应用程序”相关的错误
ExecJS::ProgramError in Welcome#index
Showing E:/scabase/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
(in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/turbolinks- 2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
【问题讨论】:
-
您的代码看起来不错。它应该向
https://localhost:3000/articles/:id发送一个DELETEHTTP 请求。单击链接时是否出现错误?我们需要更多信息来帮助调试。 -
感谢您提供更多信息——当您单击链接时,我仍然对实际发生的情况感到有些困惑?您是否被带回您之前所在的页面,或者您是否收到错误消息?您还可以在
rails server运行的终端中查看日志,看看是否可以找到请求被路由到ArticlesController 的destroy 方法的位置。
标签: ruby-on-rails ruby