1

I'm trying to follow the rails getting started guide http://guides.rubyonrails.org/getting_started.html to create a blog for a small website i've developed in rails

I've read many similar questions on SO but i'm still not able to figure out why i keep getting the error The action 'show' could not be found for CommentsController error when trying to destroy a comment as done in the guide.

Here's my link in my html.erb code:

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

My template header has these lines

<%= 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' %>

My gemfile contains this:

gem 'jquery-rails'

I've also noticed that when i load the page with the destroy comment link on it, there is this error in the firebug console:

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

Any help on figuring out this issue is appreciated. Let me know if you want anything else posted.

EDIT: Manifest file.

// 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 do

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

resources :posts do resources :comments end

root :to => 'home#index' end

4

2 回答 2

3

Was there a reason that you got rid of the javascript include in the tutorial? (not a snarky question - just curious). Try adding this line to app/views/layouts/application.html.erb.:

<%= javascript_include_tag "application" %>

The problem you are having really smells like the javascript function that fakes sending a DELETE request is missing/malfunctioning.

于 2012-05-07T00:51:48.803 回答
1

try this in your routes

resources :posts do
  resources :comments, :only => [:create, :destroy]
end
于 2012-05-04T02:46:24.803 回答