简体   繁体   English

在Rails中渲染两个模型JSON,以实现有角度的前端

[英]Render two model json in rails for angular front end

Very new to angular on rails. 在铁轨上非常新。 Basic app idea is to let anyone view venues. 应用的基本想法是让任何人都可以查看场地。 Click on venues. 点击场地。 Make comments. 发表评论。 At the moment I have a single model: venue. 目前,我有一个模型:场地。 Hard-coded data. 硬编码数据。 Full crud. 全结实。 Renders as JSON. 呈现为JSON。 Basically I want nested resources. 基本上我想嵌套资源。 Comments are not useful except in the context of the venue they belong to. 注释仅在其所属场所的上下文中有用。 I'm trying to find information about how I should create associations in rails api. 我正在尝试查找有关如何在Rails api中创建关联的信息。 Like does the venue have many comments such that active record knows about it? 场地是否有很多评论,以便活动记录可以知道? Or do I just pass comments as a hash attribute to the single venue model, and if so, how? 还是只将注释作为哈希属性传递给单个场所模型,如果是,如何?

Use ActiveModelSerializers. 使用ActiveModelSerializers。 You can override attributes data structures in any format and can easily use nested resources. 您可以覆盖任何格式的属性数据结构,并且可以轻松使用嵌套资源。 https://github.com/rails-api/active_model_serializers https://github.com/rails-api/active_model_serializers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM