【发布时间】:2014-03-27 18:16:53
【问题描述】:
undefined method `post_comments_path' for #<#<Class:0x4e6ec28>:0x4e6e3d0>
我在创建与帖子关联的评论时遇到此错误。
<%= form_for([@post, @post.comments.build]) do |f| %>
上面是我收到错误的表单部分..
我在 cmets 控制器中的代码:
def create
@post = Post.find (params[:post_id])
@comment = @post.comments.create(params[:comments].permit(:commenter, :body))
redirect_to post_path(@post)
end
请指出我错在哪里。我是 ruby on rails 的新手。
我的路线.rb:
Blog::Application.routes.draw do
resources :posts
resources :comments
root to:"welcome#index"
get "welcome/index"
我的 rake 路线:
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PATCH /posts/:id(.:format) posts#update
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
comments GET /comments(.:format) comments#index
POST /comments(.:format) comments#create
new_comment GET /comments/new(.:format) comments#new
edit_comment GET /comments/:id/edit(.:format) comments#edit
comment GET /comments/:id(.:format) comments#show
PATCH /comments/:id(.:format) comments#update
PUT /comments/:id(.:format) comments#update
DELETE /comments/:id(.:format) comments#destroy
root GET / welcome#index
welcome_index GET /welcome/index(.:format) welcome#index
我编辑的路线.rb ::
Blog::Application.routes.draw do
resources :post do
resources :comments
end
root to:"welcome#index"
get "welcome/index"
end
【问题讨论】:
标签: ruby-on-rails ruby