Schemaless design for Ember data in Ember.js - ruby-on-rails

We are having schemaless database on MongoDB in Rails. I want to know how to use such a schemaless emberjs data design to integrate with such a design.
I am not able to find any documentation on if this can be achieved or if there is any best practice
Can any one help me with this ?
EDIT:
Question is on how to use EmberJS persistent datastore for a schemaless MongoDB Rails backend.

The first two links below should help. See how the first link is setting primaryKey: '_id' to recognize mongodb _id and the second link shows how to make active_model_serializer gem work with mongoid, the gem is ember-core team's recommended gem for working with rails and ember-data :
https://github.com/dagda1/workoutzenith/tree/master/app/models
https://github.com/dagda1/workoutzenith/blob/master/config/initializers/active_model_serializer_mongoid_initializer.rb
If you run into problems with embedded mongodb documents and ember-data, this should solve it:
Ember-data embedded objects stored as separate objects
Read the link below and also examine the github project:
http://tardate.blogspot.co.uk/2012/03/rails-ember-mongodb-bootstrap.html
https://github.com/evendis/rails-ember-mongo-bootstrap-demo
This is not using rails but nodejs, mongodb and emberjs. The mongodb + emberjs might still be useful to you
https://github.com/abelaska/nodejs-emberjs-mongodb

There is still no clear and scalable solution I see of how to apply Ember to scenario where the Rails backend database like MongoDB stores document of any depth with unknown fields.
There are some ways of normalizing but still with existing REST/REST+DS we may have to write a lot of code to serialize and de serialize.
Take a peek on the discussions:
https://github.com/emberjs/data/issues/53#issuecomment-9196555
https://github.com/emberjs/data/issues/100
If some one finds a better pick, please share with me.

Jus follow the links http://robert-reiz.com/2012/03/05/rails-mongodb-tutorial/, http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started

Related

mongoid: how to store an encrypted BSON::Binary field?

I started using mongodb in my application and I'm now looking for an easy way to encrypt some sensitive binary data and store it in the mongodb.
When I do it for my MySql DB I use the attr_encrypted, but I guess that with mongoid, I'll need some other gem or method to do it, especially with a non-string field (BSON::Binary ).
Any suggestions?
Firstly attr_encrypted works with Mongoid/other DataMappers. it is similar to how you use it with SQL.
Otherwise, you can always check out the rails library for basic Encryption.
But, if you're looking for a specific gem that works with mongoid, you can go with either of these two options - (I have not included old/inactive gems but you can check out a complete list here)
symmetric-encryption
Here's a how-to blog.
This one isn't Mongoid specific though.
The second option is mongoid-encrypted-fields
It is mongoid specific, albeit a little less popular. More info here.
Hope this helps! :)

MongoDB with PostgreSQL in One Rails App

Can I use MongoDB and a PostgreSQL in one rails app? Specifically I will eventually want to use something like MongoHQ. So far I have failed to get this working in experimentation. And it concerns me that the MongoDB documentation specifically says I have to disable ActiveRecord. Any advice would be appreciated.
You don't need to disable ActiveRecord to use MongoDB. Check out Mongoid and just add the gem plus any models along side any of your existing ActiveRecord models. You should note that MongoHQ is just a hosting service for MongoDB and can be used alongside any Object Document Mapper (ODM).
For further details check http://mongoid.org/en/mongoid/docs/installation.html. Just skip the optional 'Getting Rid of Active Record' step.
On a recent client site I worked with a production system that merged MySQL and MongoDB data with a single Java app. To be honest, it was a nightmare. To join data between the two databases required complex Java data structures and lots of code, which is actually databases do best.
One use-case for a two database system is to have the pure transactional data in the SQL database, and the aggregate the data into MongoDB for reporting etc. In fact this had been the original plan at the client, but along the way the databases became interrelated for transactional data.
The system has become so difficult to maintain that is is planned to be scrapped and replaced with a MongoDB-only solution (using Meteor.js).
Postgres has excellent support for JSON documents via it's jsonb datatype, and it is fully supported under Rails 4.2, out of the box. I have also worked with this and I find it a breeze, and I would recommend this approach.
This allows an easy mix of SQL and NoSQL transactions, eg
select id, blast_results::json#>'{"BlastOutput2","report","results","search","hits"}'
from blast_caches
where id in
(select primer_left_blast_cache_id
from primer3_output_pairs where id in (185423,185422,185421,185420,185419) )
It doesn't offer the full MongoDB data manipulation features, but probably is enough for most needs.
Some useful links here:
http://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails
https://dockyard.com/blog/2014/05/27/avoid-rails-when-generating-json-responses-with-postgresql
There are also reports that it can outperform MongoDB on json:
http://www.slideshare.net/EnterpriseDB/the-nosql-way-in-postgres
Another option would be to move your Rails app entirely to MongoDB, and Rails has very good support for MongoDB.
I would not recommend running two databases, based on personal observations on how it can go bad.

Can we mix Mongodb dynamic attributes to an ActiveRecord model?

We are using a dynamic attributes plugin similar to this:
http://codaset.com/joelmoss/dynamic-attributes
Which allows us to store dynamic attributes in our rails model. Those dynamic attributes are in a single database column. We are facing performance issues because of this and I am wondering if MongoId, MongoMapper or other rails plugins will allow us to keep some attribute in ActiveRecord (keeping the < ActiveRecord::Base) but store the dynamic attributes in mongodb. We want to do this because we need to keep using MySQL for most of our existing system, but use MongoDB to store dynamic attributes about some models.
Basically this is what I am talking about:
http://www.railsinside.com/plugins/242-quickly-add-couchdb-to-existing-rails-models-with-stuffing.html
This plugin does the exact same thing using CouchDB.
I don't see any reason that MongoDB can't handle the same thing.
MongoMapper should implement the ActiveRecord pattern. However, Mongo also has some simple drivers for Ruby. All in all, the concept of storing dynamic attributes is a perfect use-case for MongoDB.
If you don't mind skipping "ActiveRecord" you can probably cook up your own using the basic Mongo drivers with very little work.
If you can't figure out the steps to do this, I would suggest pinging the groups (http://groups.google.com/mongodb-user/) and asking Kyle Banker directly (he's their ruby expert).

How can I export a rails model to json schema?

I am looking to optimize how we build forms for some of our models and ideally I would like to build them from json-schema.
Is there a gem or the like which would allow me to export a model definition to json-schema?
Bonus: With validations.
Bonus: While modelling association relationships.
I am working on a gem that creates models based on a JSON Schema: jsonmodel
And I am also working on support for formtastic in a separate gem: jsonmodel-formtastic
Please note that both are a work in progress, but it would be nice to get feedback :-)
Formtastic: http://github.com/justinfrench/formtastic has a mechanism for building forms from the models. Maybe you could base your code on theirs.
Check in lib/formtastic.rb line 474 or so.
Railscast for formtastic: http://railscasts.com/episodes/184-formtastic-part-1
I dont know about a gem that does this, but you could either pull the SQL or Rails schema data and then parse it, even easier if you're working with thw rails schema, as you can parse it by running it in a Ruby DSL.

Pattern to model wiki-type functionality

Is there a pattern or a gem (Ruby on rails) for modeling the wiki-like behaviour of a StackOverflow like web site?
I'm working on Ruby-on-Rails project so a gem or something in RoR would be appreciated but a well defined pattern is just as good.
Thanks
Did you try act_as_versioned? It is available as a gem, and adds simple versioning to any ActiveRecord model.
If you need more features, act_as_revisable might be interesting. According to the link, it adds the following features on top of act_as_versioned:
Pervasive Callbacks
Branching and Changesets
Deletes can be stored as a revision
Explicit is better than implicit
All data for a model is stored in one table
Wrapping up, requirements and installing

Resources