我正在尝试使用数组填充formtastic选择菜单。
PAYMENT_METHODS = %w[creditcard check money-order cash western-union]
<%= f.input :payment_methods, :as=>:select, :collection => User::PAYMENT_METHODS%>
它有效,但现在就出现了。
<select>
<option value="creditcard">creditcard</option>
<option value="western-union">western-union</option>
</select>
相反,我希望它看起来像:
<select>
<option value="creditcard">Credit Card</option>
<option value="western-union">Western Union</option>
</select>
我怎样才能让它发挥作用?
答案 0 :(得分:1)
我无法测试它,但我认为你可以这样做。
%w[Credit\ Card Check Money \Order Cash Western\ Union]
来自Programming Ruby文档。
<强>更新强>
回顾formtastic Github页面上的选择示例后,我相信你可以做到这一点。和以前一样,它没有经过测试。
<%= f.input :payment_methods, :as=>:select, :collection => { "Credit Card" => "creditcard", "Check" => "check", "Money Order" => "money-order", "Cash" => "cash" "Western Union" => "western-union" >