未初始化的常量Admin :: CommentsController

时间:2014-04-04 00:14:13

标签: ruby-on-rails ruby-on-rails-4

有帖子和其他资源很少有评论(多态关联)

  

/ admin / posts / 1 / comments / new

的ActionController :: RoutingError

路由

namespace :admin do
  resources :posts do
    resources :comments
  end
end

<%= link_to "Comment", [:new, @commentable, :comment] %>

posts_controller

def show
  @post = Post.find(params[:id])
  @commentable = @post
  @comments = @commentable.comments
  @comment = Comment.new
end

1 个答案:

答案 0 :(得分:3)

这意味着您没有Admin::CommentsController,即CommentsController应位于Admin名称空间下。

例如:CommentsController类应定义为:

class Admin::CommentsController < ApplicationController
   .....
end

另外,请将comments_controller.rb放在app/controllers/admin目录下。