2

我有以下代码:

= 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

那怎么会发生?

4

3 回答 3

3

像这样的东西(来自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
于 2013-07-14T10:32:51.660 回答
0

您需要使用数组数组:

[[100, "One Hundred"], [200, "Two Hundred"], [300, "SPARTA!"]] 

然后,您可以分别设置值和标签。

于 2013-07-14T10:30:14.803 回答
0

试试这个,对我有用:

= 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
于 2013-07-14T10:47:13.463 回答