在现有代码库中,discount模型的一个属性是discount_type. 由于此系统中仅使用 2 种类型的折扣(百分比和现金),因此它们被硬编码为percentage或cash在整个系统中,没有discount_types表或任何可映射的东西。
在表单中,有以下代码:
=form_for @discount do |f|
...
=f.select :discount_type, options_for_select(["percentage", "cash"])
...
这对新的折扣很有用,但是当拉起表单来编辑折扣时,percentage无论discount对象discount_type是什么,它总是被选中。我们如何让表单默认为discount_type正在编辑的对象的?