3
在現有的代碼庫中,discount
模型的一個屬性爲discount_type
。由於在這個系統中只有兩種類型的折扣(百分比和現金),所以它們在整個系統中被硬編碼爲percentage
或cash
,沒有discount_types
表或任何要映射到的東西。Rails窗體編輯中的選擇幫助編輯
在形式,有以下代碼:
=form_for @discount do |f|
...
=f.select :discount_type, options_for_select(["percentage", "cash"])
...
這對新折扣的偉大工程,但拉起來的時候表單編輯打折,percentage
總是選擇,不管是什麼discount
對象discount_type
是。我們如何將表單默認爲正在編輯的對象的discount_type
?
是的,不知道爲什麼我沒有在任何地方找到...太容易了。 – 2012-07-20 19:10:24