1

I have a resource nested in another:

resource :users do
  resource :posts
end

The official guide says I should have this url:

/users/:id/posts/:id

To show update edit or delete the posts. But in fact I have:

ruby-1.9.2-p290 > app.users_posts_path(1,2)
=> "/users/posts.1?=2" 

What's going wrong?

5
  • Please say where exactly in which guide you are seeing that. Commented Oct 26, 2011 at 14:20
  • guides.rubyonrails.org/routing.html#nested-resources Commented Oct 26, 2011 at 14:21
  • /users/:id/posts (note the plural on posts) implies all posts for that user but if you want to show/edit/update/delete the post then it's /user/:id/post/:id Commented Oct 26, 2011 at 14:22
  • an edge case might be 'delete_all' for deleting all posts but I am actually not sure off-the-bat how that will relate to the routes issues. Commented Oct 26, 2011 at 14:23
  • But I HAVE /users/posts.:id=:id, not /user/:id/post/:id or something other. Commented Oct 26, 2011 at 14:24

2 Answers 2

2

You need to be using standard plural routes, not singular, so use resources instead of resource:

resources :users do
  resources :posts
end
Sign up to request clarification or add additional context in comments.

Comments

0

Did you try to see your routes? in you console type:

$ bundle exec rake routes

Usually user_posts_path is the GET request for listing items (are you sure that in your route name user is plural?), so you just need to provide the first parameter that represents your :id, related to users.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.