[英]how to add an association between has_many through models in a form?
I have Groups and PhoneNumbers models connected with a has_many through relationship called group_phone_numbers. 我有通过称为group_phone_numbers的关系与has_many连接的Groups和PhoneNumbers模型。
Basically, on a group edit view, I want a list of phone_numbers with add or remove links next to them. 基本上,在组编辑视图上,我想要一个在其旁边带有添加或删除链接的phone_numbers列表。 When someone clicks add, it creates an association between the models and when someone clicks remove, it removes it. 当有人单击添加时,它会在模型之间创建关联,而当有人单击删除时,它会将其删除。 Is the proper way to do this by using a form? 通过使用表格来执行此操作的正确方法吗? Or should I just do a link_to a custom controller action? 还是我应该做一个link_to自定义控制器动作?
http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast is what you need. 您需要http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast 。 fields_for
specifically... fields_for
特别...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.