Using form_for and has_many associations with a controller in its own subdirectory


#1

Hi,

I’m trying to create a Blog in it’s own subdirectory for an E-commerce
site. Everything is hooked up just fine for the basic posting, but
when I try to add Comments, I’m getting all sorts of headaches! I’m
referring to the screencast by Ryan B. on the rubyonrails.org site.

Basically, my controller is Blog::Comments, in my Blog::Post comment
form I have this line:

<% form_for [@post, Blog::Comment.new] do |f| %>

Which throws this error:

undefined method `blog_post_blog_comments_path’ for #<ActionView::Base:
0x25ad3fc>

The path that I think I need is 'blog_post_comments_path", and I’m not
sure if this is a routing issue or something else?

Or, if I try this line:

<% form_for [@post, :Comment.new] do |f| %>

I get this error:

uninitialized constant ActionView::Base::CompiledTemplates::Comment

I’m guessing it couldn’t find the Comment Controller because it is
actually Blog::Comment

Currently, I have this in my routes file:

map.namespace :blog do |blog|
blog.resources :posts, :has_many => :comments
end

Any advice would be greatly appreciated, thanks!