我的form_for
模型Order
再次has_many :services, :through => :requests
。这是我如何映射关系的布局:
__________ _________
| Customer | | Utility |
---------- ---------
|| ^ /\
|| | ||
\/ | /\
_______ _________ _________
| Order | <=====< | Request | >=====> | Service |
------- --------- ---------
\/
||
\/
_________
| Company |
---------
其中:
---> = belongs_to
===> = has_many
<==< join model >==> = has_many, :through
在我的订单表格中,我希望有一组代表可用服务的复选框,即使复选框由Company
标记并按Utility
分类,{{1订单完成后,最终会得到Order
关联(因为这确实是客户订购的内容:公司提供的是一个公用事业公司)。
我如何在表格中完成此操作?
表单视图:
Service
其中:
- form_for @order do |order_form|
-# order form inputs, etc.
- order_form.fields_for :customer do |customer_form|
-# customer form inputs
- order_form.fields_for :services do |services_form|
%dl
- @services.each do |service_name, services|
%dt= service_name
- services.each do |service_item|
%dd
=# check_box ??????????
=# label ??????????, Company.find(service_item.company_id).name
%p= order_form.submit 'Create Order'