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 に答える