Destroy链接正在寻找节目

时间:2016-11-27 16:16:37

标签: ruby-on-rails-3.2

我的Rails应用程序出现问题;特别是我的'销毁'链接带我到展会页面。 Destroy几个小时前就已经开始工作了(我试过了),但从那以后显然搞砸了。我是Rails的一名相对初学者,他已经浏览了文档和本网站,试图找出如何自己修复问题而没有成功。其他人也有类似的问题,我已经应用了适用于他们的修复程序,但也没有解决问题。希望比我更先进的人能够发现这个问题!我使用的是Rails v3.2.8。

在index.html.erb中,我有:

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

在schools_controller.rb中,我有:

def destroy
 @school = School.find(params[:id])
 @school.destroy

 respond_to do |format|
  format.html { redirect_to schools_url }
  format.json { head :no_content }
 end
end

这就是我在Rails服务器中看到的内容:

Started GET "/schools/7" for 127.0.0.1 at 2016-11-27 16:02:55 +0000
Processing by SchoolsController#show as HTML
  Parameters: {"id"=>"7"}
  School Load (0.0ms)  SELECT "schools".* FROM "schools" WHERE "schools"."id" = ? LIMIT
1  [["id", "7"]]
  Rendered schools/show.html.erb within layouts/application (1.0ms)
Completed 200 OK in 19ms (Views: 17.0ms | ActiveRecord: 0.0ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2016-11-27 16:02:5
6 +0000
Served asset /application.css - 304 Not Modified (0ms)


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2016-11-27 16:02:56
 +0000
Served asset /application.js - 304 Not Modified (0ms)

我的application.html.erb有:

  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>

Application.js有:

//= require jquery
//= require jquery_ujs
//= require_tree .

有没有人有任何想法? 谢谢,凯瑟琳

2 个答案:

答案 0 :(得分:0)

在index.html.erb中,我将link_to更改为button_to,并且工作正常。

答案 1 :(得分:0)

请在链接上交叉检查你应该是这样的:

 <%= link_to "REMOVE", remove_path , method: :delete %>