开发者

How can I export a rails model to json schema?

开发者 https://www.devze.com 2023-01-04 02:56 出处:网络
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开发者_运维技巧.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号