1
再次,我有我的form_for
爲我的Order
模型,其中has_many :services, :through => :requests
。這裏有一個如何我有我的關係映射佈局:凡RoR:在form_for複選框爲has_many,:通過一個加入模型
__________ _________
| Customer | | Utility |
---------- ---------
|| ^ /\
|| | ||
\/ | /\
_______ _________ _________
| Order | <=====< | Request | >=====> | Service |
------- --------- ---------
\/
||
\/
_________
| Company |
---------
:
---> = belongs_to
===> = has_many
<==< join model >==> = has_many, :through
在我的訂單,我希望能有代表提供的服務複選框的數組,這樣,即使當訂單完成時(因爲這實際上是客戶訂購的:一家公司提供一種實用工具,這是一項服務),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'
其中:
@services = Service.all.to_set.classify { |service_item| Utility.find(service_item.utility_id).name }
如果只有賴安貝茨的Railscasts才能解決生活中的所有問題......那就是生活。謝謝;這正是我需要的! – neezer 2009-11-16 16:36:34