|Using only ruby driver to build rails apps?||Shan||4/3/12 12:03 PM|
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.
|Re: Using only ruby driver to build rails apps?||Kyle Banker||4/3/12 1:23 PM|
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.
|Re: Using only ruby driver to build rails apps?||Shan||4/3/12 1:39 PM|
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.
This would help me get started.
|Re: Using only ruby driver to build rails apps?||Kyle Banker||4/10/12 2:21 PM|
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: