在3台轨道上相关
我必须创建第三个表,并用第二个表进行了安装。
1st table: Schema
2nd table: Entity
3rd table: Fields
它们之间的关系是:
Schema(id) ===> Entity
Entity(id) ===> Fields
我已经创建了表格和视图直到实体,但不知道如何为
具有值的字段创建表:
"clientId"
"name"
"description"
"mnemonic"
"columnType"
"display"
"fallbackId"
"conceptDisplay"
"businessName"
帮助我创建模型和视图以显示与实体相关的所有fiels:
我尝试了一些东西像这样:
entity.rb =>型号
class Entity < ApplicationRecord
belongs_to :schema
has_many :fields, dependent: :destroy
end
field.rb =&gt;模型
class Field < ApplicationRecord
belongs_to :entity
end
schema.rb =&gt; 字段的模型
class Schema < ApplicationRecord
has_many :entities, dependent: :destroy
has_many :fields, through: :entities
validates :name, presence: true, uniqueness: true
validates :schemaId, presence: true, uniqueness: true
end
控制器:
class FieldsController < ApplicationController
def index
@field = Schema.find_by(id: params[:id]).fields
end
end
实体的视图,我必须创建link_to以显示该实体的所有字段
<div class="content">
<ul>
<% @entities.each do |data| %>
<li>
<%= data.clientId %>
<%= link_to data.name, fields_index_path(id: data.id) %>
<%= data.description %>
<%= data.mnemonic %>
</li>
<% end %>
</ul>
</div>
I have to create 3rd table having assosisted with 2nd.
1st table: Schema
2nd table: Entity
3rd table: Fields
Relation between them is:
Schema(id) ===> Entity
Entity(id) ===> Fields
I have created table and views till Entity but don't know how to create table for field
Fields having values as:
"clientId"
"name"
"description"
"mnemonic"
"columnType"
"display"
"fallbackId"
"conceptDisplay"
"businessName"
Help me to create model and views for it to show all the fiels related to entity:
I tried something like this:
entity.rb => model
class Entity < ApplicationRecord
belongs_to :schema
has_many :fields, dependent: :destroy
end
field.rb => model
class Field < ApplicationRecord
belongs_to :entity
end
schema.rb => model
class Schema < ApplicationRecord
has_many :entities, dependent: :destroy
has_many :fields, through: :entities
validates :name, presence: true, uniqueness: true
validates :schemaId, presence: true, uniqueness: true
end
controller for field:
class FieldsController < ApplicationController
def index
@field = Schema.find_by(id: params[:id]).fields
end
end
views for entity where i have to create link_to to show all field for that entity
<div class="content">
<ul>
<% @entities.each do |data| %>
<li>
<%= data.clientId %>
<%= link_to data.name, fields_index_path(id: data.id) %>
<%= data.description %>
<%= data.mnemonic %>
</li>
<% end %>
</ul>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建这些迁移:
并将所有必要的关联添加到模型中
获取所有
字段
forschema
通过eNTITY
在yout Controller中,并呈现所有链接到您的字段中的视图
,并向您的
路由添加必要的资源
You need to create these migrations:
And add all necessary associations to your models
Fetch all
fields
forSchema
throughEntity
in yout controllerAnd render all links to your fields in view
And add necessary resources to your
routes