私はこのルートファイルを持つエンジンを持っています:
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
名前空間をコントローラーのどこに魔法のように追加しているかは本当にわかりません。また、これを解決する方法もわかりません。