为 HABTM 选择多个框 [英] Select many box for HABTM

查看:28
本文介绍了为 HABTM 选择多个框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型;问题和类别之间具有 HABTM 关联.现在我想要一个表格,我可以在其中编辑问题类别,但是我不知道如何.我从这个开始,但我迷路了,我不确定如何命名名称"属性等,以及如何使用问题自动编辑/创建它,我该如何设置?

I have two models; question and category which have a HABTM association between them. Now I want to have a form where I can edit the questions categories, however I don't know how. I started with this but I am lost, I am unsure on what to name the "name" attributes etc and how it is automatically edited/created with the question, how do I set this up?

<%= f.fields_for :categories do |categories_form| %>
        <%= categories_form.select "category_ids", Category.all.collect { |c| [c.description, c.id] }, {}, {:multiple => true, :size => 9} %>
    <% end %>

我设法设置了问题(has_many) --> 用fields_for 和accepts_nested_attributes_for 回答,但不是这个.

I managed to set up question(has_many) --> answer with fields_for and accepts_nested_attributes_for, but not this.

推荐答案

您应该看看以下 Ryan Bates 的截屏视频 嵌套模型表单第 1 部分嵌套模型表单第 2 部分.

You should take a look at the following screencasts by Ryan Bates Nested Model Form Part 1 and Nested Model Form Part 2.

这篇关于为 HABTM 选择多个框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆