How can I export a rails model to json schema?

六眼飞鱼酱① 提交于 2019-12-04 14:01:24

问题


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.


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/3068792/how-can-i-export-a-rails-model-to-json-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!