我有以下代码:
= simple_form_for :credits, url: "/accounts/#{@account.id}/topup" do |f|
= f.input :amount, collection: [100,500,1000,5000,10000],as: :radio_buttons
= f.button :submit
它可以设置集合中的所有值和标签。我想要的是类似的东西,
label: 100, value: 500
那怎么会发生?
我有以下代码:
= simple_form_for :credits, url: "/accounts/#{@account.id}/topup" do |f|
= f.input :amount, collection: [100,500,1000,5000,10000],as: :radio_buttons
= f.button :submit
它可以设置集合中的所有值和标签。我想要的是类似的东西,
label: 100, value: 500
那怎么会发生?
像这样的东西(来自simpleform github)。
他们的例子是:
form_for @user do |f|
f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end
和
所以我认为你的应该看起来像:
= simple_form_for :credits, url: "/accounts/#{@account.id}/topup" do |f|
= f.collection_check_boxes :amount, [[100, 500], [500, 'a'], [1000, 'b'], [5000, 'c'], [10000, 'd']]
= f.button :submit
您需要使用数组数组:
[[100, "One Hundred"], [200, "Two Hundred"], [300, "SPARTA!"]]
然后,您可以分别设置值和标签。
试试这个,对我有用:
= simple_form_for :credits, url: "/accounts/#{@account.id}/topup" do |f|
= f.input :amount, collection: [['100','500'], ['1000','5000'] ,['10000', '23']], as: :radio_buttons
= f.button :submit