我收到这个错误:
undefined method `post_comments_path' for #<#<Class:0x1052a6e98>:0x1052a4be8>
Extracted source (around line #27):
24:
25: <% end%>
26:
27: <% form_for [@post, Comment.new] do |f| %>
28: <p>
29:
30: <%= f.label :name, "Author" %><br />
Run Code Online (Sandbox Code Playgroud)
我的路线:
Myblog::Application.routes.draw do
root :to => 'posts#index'
resources :comments
resources :posts, :has_many => :comments
Run Code Online (Sandbox Code Playgroud)
post.rb
class Post < ActiveRecord::Base
has_many :comments
end
Run Code Online (Sandbox Code Playgroud)
comment.rb
class Comment < ActiveRecord::Base
belongs_to :post
end
Run Code Online (Sandbox Code Playgroud)
意见/职位/ show.html.erb
<p id="notice"><%= notice %></p>
<p>
<b>Title:</b>
<%= @post.title %>
</p>
<p>
<b>Body:</b>
<%= @post.body …Run Code Online (Sandbox Code Playgroud)