【发布时间】:2010-08-22 20:59:02
【问题描述】:
我有一个评论表单(在 cmets/_form.html.erb 中),我在其他控制器(帖子和标签)中使用它。
<% 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 %>
在我的评论模型中,我有:
belongs_to :post
在我的应用程序的 rails 2 版本中,我的 routes.rb 包含 map.resources :posts, :has_many => :comments,它运行良好,但 Rails 3 中的相同配置会引发未定义的方法错误:
undefined method `post_comments_path' for #<#<Class:0xf94920>:0xf8d540>
我认为 Rails 2.x 路线只是在 3.1 发布之前贬值。如何将其转换为 Rails 3?感谢您阅读我的问题。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routes nested-routes