Rails:使用选择框填充三重联接表
我有一个域模型,其中包含与此非常相似的三重连接: Triple join in Ruby on Rails
我已经按照接受的答案所建议的方式实现了模型,但是我正在努力实现用于填充组表的表单。
我的表单需要提供一种将多个成员身份分配给该组的方法。我正在使用的设计通过一组两个选择框来实现这一目标,一个用于用户,一个用于角色。我尝试使用类似于以下的代码添加多组选择框:
<%= select 'group','users', User.all.collect {|u| [u.display_name, u.id]} %>
<%= select 'group', 'roles', Role.all.collect {|r| [r.name, r.id]} %>
<br />
<%= select 'group','users', User.all.collect {|u| [u.display_name, u.id]} %>
<%= select 'group', 'roles', Role.all.collect {|r| [r.name, r.id]} %>
但是,Rails 只将最后一组选择中的值传递到控制器中。有没有办法在具有多个选择的单个表单中创建连接表的多个实例?对于这样的表单,创建操作会是什么样子?
I have a domain model which includes a triple join very similar to this: Triple join in Ruby on Rails
I have implemented the models as suggested by the accepted answer, however I'm struggling to implement a form for populating the groups table.
My form needs to provide a way to assign multiple memberships to the group. The design I am working with achieves this with sets of two select boxes, one for a user and one for a role. I have tried adding multiple sets of select boxes with code similar to this:
<%= select 'group','users', User.all.collect {|u| [u.display_name, u.id]} %>
<%= select 'group', 'roles', Role.all.collect {|r| [r.name, r.id]} %>
<br />
<%= select 'group','users', User.all.collect {|u| [u.display_name, u.id]} %>
<%= select 'group', 'roles', Role.all.collect {|r| [r.name, r.id]} %>
However, Rails only passes the values from the last set of selects into the controller. Is there a way to create multiple instances of a join table inside a single form with multiple selects? What would the create action look like for such a form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论