views:

190

answers:

1

I have a comment form (in comments/_form.html.erb) that I use in my other controllers (posts and tags).

<% form_for([@post, Comment.new], :html => { :multipart => true }) do |f| %>

    <%= f.text_field :commenter %>

    <%= f.text_field :email %>

    <%= f.text_area :body %>

    <%= f.submit 'submit' %>

<% end %>

In my Comment model I have:

belongs_to  :post

In the rails 2 version of my application my routes.rb included map.resources :posts, :has_many => :comments which worked fine but the same configuration in Rails 3 throws an undefined method error:

undefined method `post_comments_path' for #<#<Class:0xf94920>:0xf8d540>

I thought Rails 2.x routes were just depreciated until 3.1 comes out. How do I convert this to Rails 3? Thanks for reading my question.

+2  A: 

In Rails 3, you can define nested routes as such:

resources :posts do
  resources :comments
end

I think you may also need to define form_for a little differently:

<%= form_for [:post, @comment] do |f| %>

Hope that helps! Check out http://rizwanreza.com/2009/12/20/revamped-routes-in-rails-3 for a bit more information about routing in Rails 3.

Sonia