- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个创建“人才文件”的表单。在这种形式中,作为单独模型的属性是“高度、体重、头发等”。对于人才概况。然而,这实际上涉及到4张表。
带有示例的表格
人才简介
id - 1
talent_profile_attributes -(将人才链接到具有值的属性)
Talent_id - 1
default_attribute_id - 2
default_attribute_value_id - 3
default_attributes -
id - 2
姓名 - “头发”
default_atrribute_values -
id - 3
default_attribute_id - 2
值-“棕色”
与模型的关系很好,我可以手动插入表中并根据需要检索每个配置文件的属性。但是,我遇到的问题是弄清楚如何以单一表单提交 TalentProfile 模型和 TalentProfileAttributes 模型。
我尝试使用accepts_nested_attributes_for,但没有成功。此外,我不太确定如何将 default_attribute_id 和 default_attribute_value_id 放入表单的字段中。任何想法或方向将不胜感激,现在已经研究了几个小时但无济于事。
基本上,我正在寻找一个显示 DefaultAttributes 表中所有值的表单,其中的下拉列表包括每个属性的 DefaultAttributeValue,并在提交时在 TalentProfileAttribute 表中创建关系。
最佳答案
弄清楚了,在模型、 View 和 Controller 中使用了它
型号
accepts_nested_attributes_for :talent_profile_attributes
Controller
def new
@talent = TalentProfile.new
@attributes = DefaultAttribute.all
@attributes.count.times { @talent.talent_profile_attributes.build }
end
查看
<% attr_i = DefaultAttribute.first.id - 1 %>
<%= f.fields_for :talent_profile_attributes do |attrf| %>
<%= attrf.label :default_attribute_value_id, @attributes[attr_i].name %>
<%= attrf.select :default_attribute_value_id,
@attributes[attr_i].default_attribute_values.collect {|p| [ p.value, p.id ] }.unshift("-") %>
<%= attrf.hidden_field :default_attribute_id, value: @attributes[attr_i].id %>
<% attr_i += 1 %>
<% end %>
关于mysql - Rails 4 一种形式的多个模型,包括键值表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21066607/
我需要一个可以解决以下问题的java程序: 1-它有一个数据结构(DS)来表示以下数据,其中行和列由字符串索引,单元格值是 boolean 值。 因此,要访问第 (i) 行,我可以简单地说 DS["Y
我有一些 SQL 表,一张用于用户,一张用于配置,一张用于用户配置的键/值。 我想要做的是,当向用户表添加新条目时,我想用一行填充配置表中所有可用配置行的键/值表。 因此,如果配置表具有以下行: Se
我继承了一个 mysql 数据库,该数据库有一个包含如下列的表: object_id, property, value 它保存这样的数据: 1,first_name,Jane 1,last_name,
我正在使用这个查询来连接我的学生表和出勤表, 我的问题是,有时出勤表没有值(value)。 它没有返回任何值。 0){ while($row=mysqli_fetch_assoc($r
我正在使用一个执行以下查询的 wordpress 网站,但我看到这个查询正在执行许多内部连接,并且该网站需要很长时间才能加载并且下降很多,我一直在尝试创建一个产生的查询同样的结果,但还没有成功 我想知
我正在使用一个执行以下查询的 wordpress 网站,但我看到这个查询正在执行许多内部连接,并且该网站需要很长时间才能加载并且下降很多,我一直在尝试创建一个产生的查询同样的结果,但还没有成功 我想知
我正在使用一个正在执行以下查询的wordpress网站,但我看到这个查询正在执行许多内部联接,并且该网站需要很长时间才能加载并且出现故障,并且我一直在尝试创建一个生成的查询结果相同,但尚未成功 我想知
这是我的 EAV 表结构(我知道 EAV 很糟糕,但我需要存储的属性数量超过一万个,因此规范化表不起作用) Table name - propertyAssign entityId - int - i
我是一名优秀的程序员,十分优秀!