1

I created a new scaffold rails generate scaffold scores score:integer route_id:integer and ran rake db:migrate.

This works well, but when I go to the scores page to delete some data the delete link somehow displays the view details, but doesn't delete it. I also compared the link with some other projects and it looks pretty much the same only that it doesn't work this time.

That's what I have in my index.html.erb page:

<td><%= link_to 'Destroy', score, method: :delete, data: { confirm: 'Are you sure?' } %></td>

I found in some posts on this site that the gem file needs to contain gem 'jquery-rails' so I checked and it is there. I also ran bundle install again, but no change. The change from link_to to button_to didn't help either.

Does anybody have an idea what else it could be? If you need more details let me know and I will be happy to add it.

Many thanks.

4

4 回答 4

1

我遇到了同样的问题,只有在我将 jquery 和 jquery_ujs 添加到我的页面后,我才设法解决它:

<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery_ujs" %>
<%= javascript_include_tag "application" %>

我很可能对资产管道有问题,因为我在 application.js 中请求了它们,但是当页面上没有明确请求它们时它不起作用。在我的 application.js 中,我有:

//= require_jquery
//= require_jquery_ujs
//= require_tree .
于 2014-02-01T18:27:50.447 回答
1

有时会发生这种情况,因为您没有在应用程序中包含 jquery_ujs。打开浏览器控制台并检查是否包含 jquery_ujs 或是否包含多次。

于 2013-05-06T08:45:10.543 回答
0

我猜method: :delete由于您提供了资源,因此将被覆盖或忽略。你能试试这个吗?

<td><%= link_to 'Destroy', destroy_score_path(score), data: { confirm: 'Are you sure?' } %></td>

以下是link_to供参考的文档:http: //api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

于 2013-05-05T18:05:16.067 回答
0

简单的。您需要在 application.html.erb 中包含 jquery_ujs,也称为 rails.js。我以前有这个问题。Rails 需要 rails.js 来执行此操作。

于 2013-12-03T22:03:38.370 回答