我有一个引擎,带有这个路由文件:
Rails.application.routes.draw do
resources :comments, :controller => 'opinio/comments'
end
当我运行rake routes
任务时,我得到了正确的输出
comments GET /comments(.:format) {:action=>"index", :controller=>"opinio/comments"}
POST /comments(.:format) {:action=>"create", :controller=>"opinio/comments"}
new_comment GET /comments/new(.:format) {:action=>"new", :controller=>"opinio/comments"}
edit_comment GET /comments/:id/edit(.:format) {:action=>"edit", :controller=>"opinio/comments"}
comment GET /comments/:id(.:format) {:action=>"show", :controller=>"opinio/comments"}
PUT /comments/:id(.:format) {:action=>"update", :controller=>"opinio/comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"opinio/comments"}
我的控制器非常简单:
class Opinio::CommentsController < ApplicationController
include Opinio::Controllers::InternalHelpers
def index
resource.comments.page(params[:page])
end
def create
@comment = resource.comments.build(params[:comment])
@comment.user = current_user
if @comment.save
flash[:notice] = I18n.translate('opinio.comment.sent', :default => "Comment sent successfully.")
else
flash[:error] = I18n.translate('opinio.comment.error', :default => "Error sending the comment.")
end
end
end
但是,当我尝试使用进入引擎控制器的任何操作时,我收到以下错误:
uninitialized constant Comment::CommentsController
我真的不知道 Rails 是在哪里神奇地Comment
在控制器上添加了这个命名空间,我也不知道如何解决这个问题。