如何将 Rails 模型导出到 json 模式?
我正在寻求优化我们为某些模型构建表单的方式,理想情况下我想从 json-schema 构建它们。
是否有 gem 或类似的东西可以让我将模型定义导出到 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我正在开发一个基于 JSON 模式创建模型的 gem: jsonmodel
我也在提供支持for formtastic 在单独的 gem 中: jsonmodel-formtastic
请注意,两者都正在进行中,但是很高兴得到反馈:-)
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 具有从模型构建表单的机制。也许您可以将您的代码基于他们的代码。
检查 lib/formtastic.rb 第 474 行左右。
Railscast for formtastic: http://railscasts.com/episodes/184-formtastic-part- 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
我不知道是否有 gem 可以做到这一点,但是您可以提取 SQL 或 Rails 模式数据,然后解析它,如果您使用的是 Rails 模式,则更容易,因为您可以通过在 Ruby DSL 中运行它来解析它。
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.