unomi
unomi

Reputation: 2672

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.

Upvotes: 6

Views: 2454

Answers (3)

Papipo
Papipo

Reputation: 2811

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

Upvotes: 2

nkassis
nkassis

Reputation: 5353

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

Upvotes: 1

thomasfedb
thomasfedb

Reputation: 5983

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.

Upvotes: 1

Related Questions