相关疑难解决方法(0)

rails 3 app中没有方法错误

我收到这个错误:

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)

ruby-on-rails ruby-on-rails-3

5
推荐指数
1
解决办法
4849
查看次数

标签 统计

ruby-on-rails ×1

ruby-on-rails-3 ×1