Using only ruby driver to build rails apps?

90 views
Skip to first unread message

Shan

unread,
Apr 3, 2012, 3:03:03 PM4/3/12
to mongodb-user
Hi,

I just started to play around with mongodb using ruby. I'm now trying
to incorporate what I have learned so far into building a rails app
because I feel that's how I learn best.

My question is, do I have to use to Object Mappers such as Mongoid/
MongoMapper or can I just use the ruby drivers. I try to keep the
minimalist approach and not add in too many things early on.

Using the ruby driver seems easy enough, but for those with
experience, is the ruby driver built with the use case of being
directly used in a rails app, or was it built to have some other
abstraction on top of it such as Mongoid/MongoMapper. etc.

Kyle Banker

unread,
Apr 3, 2012, 4:23:57 PM4/3/12
to mongod...@googlegroups.com
You can certainly use the Ruby driver directly in a Rails app. The main thing to keep in mind is that the Ruby driver doesn't support ActiveModel. This means that a lot of the various helpers that developers often use when building Rails applications won't be available to you (think of the form validation helpers, for example).

If you can live without those, you should be fine.

Shan

unread,
Apr 3, 2012, 4:39:02 PM4/3/12
to mongodb-user
Thanks for the answer. I can live without the validation helpers. I
just find that it helps me learn faster if I am not learning many
things at once.

Also, how would I extract the data using a model.

Some prelim research suggest, things like connection initialization
would come from a initializer. But I don't know how to set it up.

Do I make a new connection in every method call, or how do I do this
within the following context.

class Testing

end

This would help me get started.

Kyle Banker

unread,
Apr 10, 2012, 5:21:22 PM4/10/12
to mongod...@googlegroups.com
You only need to connect once, in the initializer. Usually, you'll have some class that wraps the connection. Here's a very simple example to get you started:
Reply all
Reply to author
Forward
0 new messages