小编use*_*822的帖子

Rails 4.0.4 中的“#<#<Class:0x4e6ec28>:0x4e6e3d0> 的未定义方法`post_comments_path'”

undefined method `post_comments_path' for #<#<Class:0x4e6ec28>:0x4e6e3d0>
Run Code Online (Sandbox Code Playgroud)

我在创建与帖子相关的评论时收到此错误。

<%= form_for([@post, @post.comments.build]) do |f| %>
Run Code Online (Sandbox Code Playgroud)

以上是我收到错误的表格部分..

我在评论控制器中的代码:

def create
  @post = Post.find (params[:post_id])
  @comment = @post.comments.create(params[:comments].permit(:commenter, :body))
  redirect_to post_path(@post)
end
Run Code Online (Sandbox Code Playgroud)

请指出我错在哪里。我是 ruby​​ on rails 的新手。

我的路线.rb:

Blog::Application.routes.draw do
  resources :posts 
  resources :comments
  root to:"welcome#index"
  get "welcome/index"
Run Code Online (Sandbox Code Playgroud)

我的佣金路线:

        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 …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

0
推荐指数
1
解决办法
1856
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1