2011-04-06 129 views
1

3引擎的問題,我有一個發動機,與此路線文件:導軌和路線

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命名空間,我沒有對如何解決這個問題的線索。

回答

2

哇,這值得回答,所以沒人像我這樣做過這樣的愚蠢。

基本上,我說這不是我的引擎模塊:

mattr_accessor :name 
@@name = "Comment" 

和境內時,已經是每一個模塊,這是我不小心overrided上的方法name,並導致所有的錯誤。 AS試圖加載缺少的常量,但在我的Opinio模型中調用name時,它得到了"Comment"而不是Opinio

提醒我自己和其他人在那裏。 不要使用明顯的名稱和屬性,也不要檢查它們是否已經先存在。