Rails无法找到CommentsController错误的操作'show'

时间:2012-05-03 02:30:52

标签: ruby-on-rails ruby ruby-on-rails-3

我正在尝试按照导航入门指南http://guides.rubyonrails.org/getting_started.html为我在rails开发的小型网站创建博客

我已经在SO上阅读了很多类似的问题,但是我仍然无法弄清楚为什么我在试图销毁评论时不断收到错误The action 'show' could not be found for CommentsController error

这是我的html.erb代码中的链接:

<%= link_to 'Destroy Comment', [comment.post, comment], :confirm => 'Are you sure you want to delete?', :method => :delete %>

我的模板标题包含以下行

<%= csrf_meta_tag %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", "rails", "superfish", "jquery.quicksand", 'slides.min.jquery' %>

我的gemfile包含:

gem 'jquery-rails'

我还注意到当我加载带有destroy注释链接的页面时,firebug控制台中出现此错误:

"NetworkError: 404 Not Found - http://localhost:3000/assets/rails.js"

对于解决此问题的任何帮助表示赞赏。如果您想要发布任何其他内容,请告诉我们。

修改: 清单文件。

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

的routes.rb

Allthingswebdesign :: Application.routes.draw做

get "about/index"
get "home/index"
get "portfolio/index"
get "contact/index"
post "contact/create"
get "contact/new"
get "posts/index"
get "posts/new"

资源:帖子做     资源:评论   端

root:to =&gt; “家#指数” 端

2 个答案:

答案 0 :(得分:3)

你有没有理由摆脱教程中的javascript包含? (不是一个讽刺的问题 - 只是好奇)。尝试将此行添加到app/views/layouts/application.html.erb.

<%= javascript_include_tag "application" %>

你真正闻到的问题就是假冒发送DELETE请求的javascript函数缺失/出现故障。

答案 1 :(得分:1)

在你的路线中尝试这个

resources :posts do
  resources :comments, :only => [:create, :destroy]
end