用户更新 has_many :通过关联
在我的应用程序中,公司管理员定义了一组与位置关联的属性(例如,市场规模和地理位置)。它们还定义了给定属性可接受的值(每个位置的每个属性只有一个值)。由于属性数量不固定,因此我使用 HMT 进行此关联。实际上,location.attributes 包含与位置关联的属性。我希望在位置视图中允许用户选择每个属性的值。我希望这些值能够更新 HMT 关联。我只能找到使用这些属性创建哈希的强力方法,用选择填充选择标签,然后处理返回到手动更新的哈希,将用户所做的选择分配给 HABTM 集合(location.attributes =参数[位置][属性])。这似乎是很常见的事情,ROR 应该有一个更内置的方法来做到这一点。我错过了一些明显的东西吗?
In my app, the administrator of a company defines a set of attributes to be associated with a location (for example, market size and geographical location). They also define which values are acceptable for a given attribute (only one for each attribute for each location). Since there is not a fixed number of attributes, I am using HMT for this association. In effect, location.attributes contains the attributes associated with the location. I want, in the location view, to allow the user to select the values for each attribute. I want those values to then update the HMT association. I can only find the brute force approach of creating a hash with those attributes, populating select tags with the choices, and then processing the hash coming back to Update manually, assigning the selections made by the user to the HABTM collection (location.attributes = params[location][attributes]). This seems like something that is common enough that ROR should have a more built-in way to do this. Am I missing something obvious?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Ingo 有正确的答案,指出我的嵌套形式铁路广播。谢谢!
@Ingo had the correct answer, pointing me to the nested forms railcasts. Thanks!