0

I'm a rails beginner struggling with routes a bit. I'm working on a Q&A site (or question and response) and any time I try to post a response, it gives the following error:

No route matches [GET] "/questions/6/responses"

Any help would be greatly appreciated, Jon

Here are the relevant bits:

Routes output (given w the error) (apologies for nasty paste):

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

Routes:

Rails.application.routes.draw do
  get 'welcome/index'

resources :users

resources :categories

resources :questions do
  resources :responses, :only => [:create]

end

root 'welcome#index'

Questions controller https://github.com/joncarpe/snack/blob/master/app/controllers/questions_controller.rb

Responses controller https://github.com/joncarpe/snack/blob/master/app/controllers/responses_controller.rb

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
joncarpe
  • 15
  • 1

1 Answers1

2

You have only route to create action in ResponsesController. If you also want route to index, you should have:

resources :responses, only: [:create, :index]

If you want routes to all default resources actions, you should abandon only option, like this:

resources :responses
Marek Lipka
  • 50,622
  • 7
  • 87
  • 91
  • Hello and thanks; sorry for the delay I got pulled out of town. I'm not sure exactly where to paste that code? I tried in the ResponsesController where the class is first defined and also under def index. What am I doing wrong. Thanks again. – joncarpe Jul 26 '14 at 16:27
  • 1
    N/m, I accidentally read your answer to mean I should make changes in the ResponsesController, not in routes.rb FOR the ResponsesController. I added your code there and it seems to have worked; now off to the next error! :) – joncarpe Jul 26 '14 at 17:15