【发布时间】:2011-04-06 11:24:55
【问题描述】:
我有一个引擎,有这个路由文件:
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 命名空间,我也不知道如何解决这个问题。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routes rails-engines