views:

44

answers:

1

Hey guys,

I have a form partial current setup like this to make new blog posts

<% form_for([@current_user, @post])  do |f| %>

This works great when editing a post, but when creating a new post I get the following error:

undefined method `user_posts_path' for #<ActionView::Base:0x6158104>

My routes are setup as follows:

map.resources :user do |user|
 user.resources :post
end

Is there a better way to setup my partial to handle both new posts and editing current posts?

+1  A: 
map.resources :user do |user|
  user.resources :posts
end

pluralize your model names in routes declaration. as you can see it says resourc-es, so you must use user-s and post-s too.

Controllers should be named UsersController and PostsController

Models should be named User and Post.

if above example still does not work for you, try a this one

map.resources :users do |u|
  u.resources :posts
end
zed_0xff
You are awesome, one of rails nuances. Thanks!
Jimmy