Rails 删除功能不起作用

lea*_*ner 0 ruby windows ruby-on-rails ruby-on-rails-4

我是 Ruby On Rails 的新手,正在阅读本指南以构建基本应用程序。

当我尝试实现文档中提到的删除功能时,我看到了显示页面。

我的控制器中有以下方法:

def destroy
  @article = Article.find(params[:id])
  @article.destroy

  redirect_to articles_path
end
Run Code Online (Sandbox Code Playgroud)

在我的页面下面一行:

<td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %></td>
Run Code Online (Sandbox Code Playgroud)

现在,当我点击链接时,我在浏览器中看到以下 URL:

http://localhost:3000/articles/1

现在,在这种情况下,我看到的是显示屏幕,而不是收到警报消息,然后从我的页面中删除记录。

我已经关注了这篇 SO post - Rails 4 link_to Destroy not working in Getting Started tutorial

并证实

//= require jquery
//= require jquery_ujs
Run Code Online (Sandbox Code Playgroud)

元素在我的 application.js

请告诉我我在哪里做错了?

更新:

这是我的rake routes命令输出:

E:\Rails\blog\bin>rake routes
(in E:/Rails/blog)
       Prefix Verb   URI Pattern                  Controller#Action
welcome_index GET    /welcome/index(.:format)     welcome#index
     articles GET    /articles(.:format)          articles#index
              POST   /articles(.:format)          articles#create
  new_article GET    /articles/new(.:format)      articles#new
 edit_article GET    /articles/:id/edit(.:format) articles#edit
      article GET    /articles/:id(.:format)      articles#show
              PATCH  /articles/:id(.:format)      articles#update
              PUT    /articles/:id(.:format)      articles#update
              DELETE /articles/:id(.:format)      articles#destroy
         root GET    /                            welcome#index
Run Code Online (Sandbox Code Playgroud)

这是我单击“删除”链接时从日志文件中得到的信息:

Started GET "/articles/3" for 127.0.0.1 at 2015-05-09 00:56:08 +0530
Processing by ArticlesController#show as HTML
  Parameters: {"id"=>"3"}
  [1m[35mArticle Load (0.0ms)[0m  SELECT  "articles".* FROM "articles"  WHERE "articles"."id" = ? LIMIT 1  [["id", 3]]
  Rendered articles/show.html.erb within layouts/application (0.0ms)
Completed 200 OK in 47ms (Views: 46.9ms | ActiveRecord: 0.0ms)
Run Code Online (Sandbox Code Playgroud)

在我的application.html.erb文件,我已经修改了文本application,以default解决我报在这篇文章的一个问题- ExecJS :: ProgramError在欢迎#指数类型错误:对象不支持此属性或方法,这是我的问题的原因呢?如果还原更改,则应用程序将完全失败。

Cha*_*nya 7

你必须使用button_to而不是link_to让它工作。

参考这篇文章 - Rails 3 - link_to :delete is redirecting to show action with jquery installed,看看 Cypher 给出的答案。