2012-01-10 83 views
0

我想用MongoMapper創建Rails 3引擎。我有一個讓人痛苦的世界。這是我的型號:用MongoMapper創建Rails引擎

module GoodComments 
    class Comment 
    include MongoMapper::Document 

    key :comment, String 

    end 
end 

超級簡單,我知道!我的config/routes.rb中

GoodComments::Engine.routes.draw do 
    resources :comments 
end 

我創建了一個的config/application.rb中

require File.expand_path('../boot', __FILE__) 

module GoodComments 
    class Application < Rails::Application 
    config.generators do |g| 
     g.orm :mongo_mapper # :active_record 
     g.template_engine :erb # :haml 
     g.test_framework :rspec, :fixture => true, :views => false 
     g.fixture_replacement :factory_girl, :dir => "spec/factories" 
    end 
    end 
end 

我跑rails generate scaffold_controller Comment -o mongo_mapper和生成我的控制器。當我運行我的服務器和去http://localhost:3000/good_comments/comments,我得到一個錯誤:

LoadError在GoodComments :: CommentsController#指數

預計/Users/shamoon/Sites/good_comments/app/models/comment.rb定義評論 Rails.root:/ Users/shamoon/Sites/good_comments/test/dummy

任何幫助?

+0

好吧..它那種工作,如果我擺脫了'模型中的GoodComments'命名空間。但scaffold'new'不讀取模型定義中的字段。 – Shamoon 2012-01-10 23:40:14

回答

1

它看起來像你的控制器期待在comment.rb中有一個名爲Comment的類,所以也許控制器需要在同一模塊中運行?或者您只需指定一些非默認配置或更具體地說明控制器應使用哪種模型。

在我MongoMapper應用

我也有幾行比你加入到配置的頂/ application.rb中

require File.expand_path('../boot', __FILE__) 

# from http://mongomapper.com/documentation/getting-started/rails.html 
# replace: 
# require 'rails/all' 
# with: 
require "action_controller/railtie" 
require "action_mailer/railtie" 
require "active_resource/railtie" 
require "rails/test_unit/railtie" 
# Uncomment for asset pipelining in Rails 3.1 
# require "sprockets/railtie"