Reputation: 43501
I'm trying to create a Rails 3 Engine using MongoMapper. I'm having a world of pain getting it going. Here is my model:
module GoodComments
class Comment
include MongoMapper::Document
key :comment, String
end
end
Super simple, I know! My config/routes.rb:
GoodComments::Engine.routes.draw do
resources :comments
end
I created a 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
I ran rails generate scaffold_controller Comment -o mongo_mapper
and my controllers were generated. When I run my server and go to http://localhost:3000/good_comments/comments
, I get an error:
LoadError in GoodComments::CommentsController#index
Expected /Users/shamoon/Sites/good_comments/app/models/comment.rb to define Comment Rails.root: /Users/shamoon/Sites/good_comments/test/dummy
Any help?
Upvotes: 0
Views: 287
Reputation: 9779
It looks like your controller was expecting a class called Comment in comment.rb, so maybe the controller needs to be operating in the same module? Or you would just have to specify some non-default configurations or be more specific about which model the controller should use.
Also in my MongoMapper app I have a few more lines than you added to the top of config/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"
Upvotes: 1