简体   繁体   English

许多表/模型属于Ruby on Rails中的一个主要模型

[英]Many Tables/models belong to one main model in Ruby on Rails

I am building an app where there is a simple model with only title and description and and that model has different forms that a user can fill and will be displayed under that same title and description in tabular form 我正在构建一个应用程序,其中有一个只有标题和描述的简单模型,并且该模型具有用户可以填写的不同形式,并将以表格形式显示在相同的标题和描述下

Example: main model being car (title: LaFerrari, Description: made by Ferrari) below it a table for engine specs with attributes (type: __, Description: __) and a few more tables. 示例:主模型是汽车(标题:LaFerrari,描述:由法拉利制造)在其下方,是带有属性(类型:__,描述:__)的发动机规格表以及其他一些表。

Every table should belong to a specific car 每张桌子应属于特定的汽车

I am not sure how to go about this problem if there is a gem or i need to create models for every table and which should belong_to main model 我不确定如果有一个gem或者我需要为每个表创建模型并且应该属于主模型,该怎么解决这个问题

A little direction would be helpful 一点方向会有所帮助

THANK YOU. 谢谢。

Table for Car 车用桌

t.string :title
t.string :description 

Model for Car 车型

has_one :engine_specs

Table for Engine Specs 发动机规格表

t.string :type
t.string :description

Model for Engine Specs 发动机规格模型

belongs_to :car

This ought to help get you started. 这应该可以帮助您入门。 Clearly though you are going to need a lot more help than this since you do not understand simple associations. 显然,由于您不了解简单的关联,因此您将需要比这更多的帮助。 I suggest you read it up by at guides.rubyonrails.org 我建议您通过guides.rubyonrails.org阅读

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

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