How can I export a rails model to json schema? - ruby-on-rails

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.

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! :)

Schemaless design for Ember data in Ember.js

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

Searching / Ordering data with inherited_resources in Rails

Is there a popular gem that makes it easier to build an admin interface in Rails that lets you search and order data? Bonus points if it integrates well with inherited_resources.
I don't want to use something as heavyweight as activeadmin.
Looking for something like this:
I found the sorted gem (https://github.com/mynameisrufus/sorted), which allows me to easily build sortable tables.
Ransack (https://github.com/ernie/ransack) lets me easily build searches.
The screenshot you provided is exactly what you are looking for
http://activeadmin.info/

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

Is there a good admin generator for Ruby on Rails?

My current project is in Rails. Coming from a Symfony (PHP) and Django (Python) background, they both have excellent admin generators. Seems like this is missing in Rails.
For those who aren't familiar with Symfony or Django, they both allow you to specify some metadata around your models to automatically (dynamically) generate an admin interface to do the common CRUD operations. You can create an entire Intranet with only a few commands or lines of code. They have a good appearance and are extensible enough for 99% of your admin needs.
I've looked for something similar for Rails, but all of the projects either have no activity or they died long ago. Is there anything to generate an intranet/admin site for a rails app other than scaffolding?
Active Admin (http://activeadmin.info/) was released in May of 2011, and looks like it's going to become the best Rails 3 option.
rails_admin appears to be the latest-n-greatest free project as of January 2011.
...best of all, there has been a lot of activity in the repository.
Scaffolding is the normal way to create an admin backend BUT there is a project called ActiveScaffold which may solve your problem.
Here is a roundup of a few options, including more than just ActiveScaffold.
ActiveScaffold is available for Rails 2.3.x :)
Just for someonse's info who have found this question one year later like me :)
ActiveScaffold is a good solution, but if you want a more configurable and powerful tool, I think Typus is a great solution:
http://github.com/fesplugas/typus
You have mainly two:
ActiveScaffolding: the most popular but be careful with rails 2.1
Streamlined
ActiveScaffold is by far and away the most configurable/easiest to integrate/most automagic scaffolding around at the moment.
It has built in ajax support, near seamless db introspection and it even plays nicely with legacy Oracle databases (which can be a real pain in Rails).
Try it: http://activescaffold.com/
Have a look at Casein (http://www.caseincms.com/), might be what you're looking for.
Having also tried typus, caseincms and ActiveScaffold over the weekend, I can't rave enough about admin_data.
It is
super-quick to install (Rails 3 is the gem, Rails 2.3 is a plugin branch,
no digging through trees on github),
unintrusive (all code is in the vendor/admin_data folder or the gem where it belongs),
requires no set-up and optional configuration is one block in one file in your app,
correctly (!) gets all model information from your model definitions (primary_key, foreign_key, relationships etc.),
including multiple databases, SQL Server connections via activerecord-sqlserver-adapter, and even composite primary keys, as everything is abstracted on top of ActiveRecord, if you model works, admin_data will work,
works great with legacy data for the above reasons,
uses your existing authentication solution which is called in the most wonderful DRYness in your configuration file.
It maybe less flexible or pretty than other solutions, but this plugin does many thingks right for quick admin panel setup.
The most common way to create a CRUD interface is to use Scaffold.
./script/generate scaffold_resource MyModel property:type property2:type2
This command would generate a CRUD interface for the model named MyModel (singular) with two properties. Properties is what's called columns in DB lingo. So you could have name:string age:integer active:boolean etc.
I can suggest you active_admin that is best
Active Admin main site

Resources