0

I am trying to set up a group of radio buttons in rails using simple_form. The options should come from a map.

In simple form, I saw there the :collection symbol can retrieve a collection (but only an array of arrays and not a hash).

How can I display a radio button collections with custom labels (ideally from a hash)?

Here is what I tried so far. Can I concatenate the symbol with an a string for a label?

#Payment.rb
OPTIONS = [[14, 19], [21,29], [30,39]] #ideally this would be a hash 

#new.html.erb
     <%= f.input :duration, 
      :collection =>  [ [14, 19.to_s], [21,29.to_s], [30,39.to_s] ], 
      :label_method => :last.concat(" days"), 
      :value_method => :first, 
      :as => :radio %>

1 Answer 1

1

if I understand your question correctly - you can use lambdas in :label_method. For example:

:label_method => lambda { |a| a.first.to_s + a.last.to_s }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.