我是一个rails初学者,有点纠结于路线。我正在一个Q& a网站(或问题和回应)工作,每当我试图发布回应时,它会给出以下错误:
No route matches [GET] "/questions/6/responses"
任何帮助都将非常感激。Jon
以下是相关的部分:
路由输出(给定错误)
Helper HTTP Verb Path Controller#Action
Path / Url
welcome_index_path GET /welcome/index(.:format) welcome#index
users_path GET /users(.:format) users#index
POST /users(.:format) users#create
new_user_path GET /users/new(.:format) users#new
edit_user_path GET /users/:id/edit(.:format) users#edit
user_path GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
categories_path GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category_path GET /categories/new(.:format) categories#new
edit_category_path GET /categories/:id/edit(.:format) categories#edit
category_path GET /categories/:id(.:format) categories#show
PATCH /categories/:id(.:format) categories#update
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
question_responses_path POST /questions/:question_id/responses(.:format) responses#create
questions_path GET /questions(.:format) questions#index
POST /questions(.:format) questions#create
new_question_path GET /questions/new(.:format) questions#new
edit_question_path GET /questions/:id/edit(.:format) questions#edit
question_path GET /questions/:id(.:format) questions#show
PATCH /questions/:id(.:format) questions#update
PUT /questions/:id(.:format) questions#update
DELETE /questions/:id(.:format) questions#destroy
root_path GET / welcome#index
路线:
Rails.application.routes.draw do
get 'welcome/index'
resources :users
resources :categories
resources :questions do
resources :responses, :only => [:create]
end
root 'welcome#index'
控制器的问题https://github.com/joncarpe/snack/blob/master/app/controllers/questions_controller.rb
反应控制器https://github.com/joncarpe/snack/blob/master/app/controllers/responses_controller.rb
您在ResponsesController
中只有路由到create
的动作。如果你还想路由到索引,你应该有:
resources :responses, only: [:create, :index]
如果你想路由到所有默认的资源动作,你应该放弃only
选项,像这样:
resources :responses