# MongoDb MongoMapper and Rails Oh MY!

**URL:** <https://www.ruby-forum.com/t/mongodb-mongomapper-and-rails-oh-my/193753>\
**Category:** Rails\
**Created:** [August 23, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/mongodb-mongomapper-and-rails-oh-my/193753 "2010-08-23T23:07:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [August 23, 2010, 11:07pm UTC](https://www.ruby-forum.com/t/mongodb-mongomapper-and-rails-oh-my/193753/1 "2010-08-23T23:07:47Z")

</div>

For the past couple of hours I am trying to insert a simple document  
into MongoDb database using Rails and MongoMapper. There is no error  
but the document never gets inserted. Here is my simple class:

class Post  
include MongoMapper::Document

key :title, String, :required =\> true  
key :description, String

end

My database.yml file:

development:  
adapter: mongodb  
host: localhost  
database: blog

test: &TEST  
adapter: mongodb  
host: localhost  
database: blog\_test

production:  
adapter: mongodb  
host: localhost  
database: blog

and my mongodb.rb file in initializer:

db\_config = YAML::load(File.read(RAILS\_ROOT + “/config/database.yml”))

if db\_config[Rails.env] && db\_config[Rails.env][‘adapter’] ==  
‘mongodb’  
mongo = db\_config[‘blog’]  
MongoMapper.connection = Mongo::Connection.new(mongo[‘hostname’])  
MongoMapper.database = mongo[‘database’]  
end

And finally here is the controller create action:

def create

```
post = Post.new
post.title = 'title'

post.save

redirect_to :action => "new"

```

end

---

<div class="post-metadata">

**Author:** ![metanoize](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9fc29f/32.png) [@metanoize](https://www.ruby-forum.com/u/metanoize)\
**Post date:** [August 23, 2010, 11:28pm UTC](https://www.ruby-forum.com/t/mongodb-mongomapper-and-rails-oh-my/193753/2 "2010-08-23T23:28:16Z")

</div>

Have you used the console to query the MongoDB database and confirm  
that a document HASN’T been made?

You could also walk through the steps to create a Post object from the  
console and see if that is successful. That should help isolate where  
the issue is.

And why are you redirecting to new rather than show for the record or  
an index of all records?

Cheers,  
Walter
