可能重複:
Why do I keep getting a routing error?運行我的Rails應用程序時,爲什麼我一直收到路由錯誤?
對不起林再次問這個,但我沒有得到任何迴應的第一次。
我試圖將註釋添加到從邁克爾·哈特爾railstutorial
在https://github.com/railstutorial/sample_app_2nd_ed發現微觀柱這裏是我的routes.rb文件有問題的區域。
resources :microposts, only: [:create, :destroy] do
resources :comments,
end
這是我收到的時候我嘗試訪問用戶頁面的錯誤:沒有路由匹配{:控制器=> 「意見」:格式=>零,:micropost_id =>#}
這裏是耙路線|的輸出grep的評論:
user_comments GET /users/:user_id/comments(.:format) comments#index
POST /users/:user_id/comments(.:format) comments#create
new_user_comment GET /users/:user_id/comments/new(.:format) comments#new
edit_user_comment GET /users/:user_id/comments/:id/edit(.:format) comments#edit
user_comment GET /users/:user_id/comments/:id(.:format) comments#show
PUT /users/:user_id/comments/:id(.:format) comments#update
DELETE /users/:user_id/comments/:id(.:format) comments#destroy
micropost_comments GET /microposts/:micropost_id/comments(.:format) comments#index
POST /microposts/:micropost_id/comments(.:format) comments#create
new_micropost_comment GET /microposts/:micropost_id/comments/new(.:format) comments#new
edit_micropost_comment GET /microposts/:micropost_id/comments/:id/edit(.:format) comments#edit
micropost_comment GET /microposts/:micropost_id/comments/:id(.:format) comments#show
PUT /microposts/:micropost_id/comments/:id(.:format) comments#update
DELETE /microposts/:micropost_id/comments/:id(.:format) comments#destroy
最後,這裏是我comments_controller.rb
class CommentsController < ApplicationController
def create
@micropost = Micropost.find(params[:micropost_id])
@comment = @micropost.comments.build(params[:comment])
@comment.user = current_user
if @comment.save
redirect_to @micropost
else
redirect_to @micropost
end
end
def show
@comment = Comment.find(params[:id])
end
def new
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
redirect_back_or root_path
end
end
你試圖訪問哪個網址導致錯誤?它*應該*看起來像'http://foo.com/microposts//comments' –
x1a4
請分享產生錯誤的網址。 –
你也有一個評論控制器? – Tyler