Reputation: 1062
I have the following code below:
= 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
It works to set all values and labels in the collection. What I want is something like,
label: 100, value: 500
How would that happen?
Upvotes: 2
Views: 5142
Reputation: 10997
Something like this (from the simpleform github).
Their example is:
form_for @user do |f|
f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
end
and
so i think yours should looks something like:
= 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
Upvotes: 3
Reputation: 1303
Try this, worked for me:
= 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
Upvotes: 0
Reputation: 14038
You need to use an array of arrays:
[[100, "One Hundred"], [200, "Two Hundred"], [300, "SPARTA!"]]
You can then set the value and label separately.
Upvotes: 0