1

Here's my problem:

  • I have a web app, in which users can create posts.

  • User and post are created simultaneously - I extract the user's email from the post to create his user entry. (No password/login/registration etc required)

  • In my routes.rb file, I have posts nested with users (see attached)

Now, here is my question:

Where should the posts#new creation form be? Currently I have it at /posts/new but this is clearly wrong, I am getting a routing error.

Grateful for any feedback.

routes.rb

Mysalary::Application.routes.draw do

resources :users do
   resources :posts
   end

resources :profiles
resources :pages

get "pages/home"
get "pages/about"
get "pages/legal"
get "pages/feedback"

root :to => 'posts#new'

end
3
  • I don't think you need to specify the posts#new as the resources would create the routes for the rest actions. Commented Apr 23, 2012 at 21:34
  • 1
    Software is (generally) case-sensitive. You shouldn't be using UPPERCASE to add emphasis because you're changing the meaning of the word by doing so. Commented Apr 23, 2012 at 21:34
  • 1
    It would be helpful if u post your error message. Commented Apr 23, 2012 at 21:35

2 Answers 2

1

I would add posts on it own, so to have both you would have:

routes.rb

resources :users do
  resources :posts
end

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

Comments

1

You have posts only as a nested resource, so you would find it at /users/:user_id/posts/new

If you want to reach it at /posts/new, just un-nest resources :posts. You can also leave it nested and repeat it outside the nesting, then it would be reachable both ways.

Remember to run rake routes in the console.

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.