2012-05-03 30 views
1

我試圖跟隨軌道入門指南http://guides.rubyonrails.org/getting_started.html創建一個博客,一個小網站我在軌道發展軌行動「秀」的CommentsController錯誤找不到

我讀過因此,許多類似的問題,但我仍然無法弄清楚爲什麼我試圖摧毀一個評論,如在指南中所做的那樣,不斷得到錯誤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' 

我也注意到當我使用銷燬註釋鏈接加載頁面時,在螢幕控制檯中出現此錯誤:

"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" 

資源:帖子做 資源:評論 結束

根:到=>' home#index' end

+0

自添加gem以來,你的運行包安裝了嗎? – natedavisolds

+0

是的,我在添加gem後運行了bundle install。 – Catfish

+0

如果沒有rails.js文件,鏈接將不會轉換爲使用刪除方法,並且確實將顯示路由。只是想確認加載這個資產是否是問題 – natedavisolds

回答

3

是否有一個原因,你擺脫了教程中的JavaScript包括? (不是一個蹩腳的問題 - 只是好奇)。嘗試添加該行app/views/layouts/application.html.erb.

<%= javascript_include_tag "application" %>

您所遇到的問題確實聞起來就像是假貨發送刪除請求缺少/故障的JavaScript功能。

+0

就是這樣。我加了這個,效果很好。我猜我意外刪除了這個時,我把我的模板進入rails代碼。 – Catfish

1

在您的路線試穿這個

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

現在,當點擊「無路由匹配[GET]」/ posts/2/comments/1「'的刪除鏈接時,我收到錯誤消息。我需要添加一些東西到我的路線文件? – Catfish

+0

好吧,出於某種原因,你是評論刪除鏈接發送獲取請求,而不是刪除。我不知道爲什麼,但我認爲如果你添加了一些東西到你的路線中,比如'match'posts /:post_id/comments /:id'=>'comments#destroy'',那會強制鏈接使用destroy方法你的comments_controller.rb。對不起,這是更多的工作,而不是「正確的方式」,但您發佈的代碼中的所有內容對我來說都很好。 –