问题
Im trying for some time to use simple_form to create the below example but + the label and fixing some styling. Anyone knows how to fix:
- remove the 2's no idea where they come from (seems strange i18n bug on production it throws a whole bunch of I18n in )
- Have the text Male or Female after the radio button
Is the result from below code:
.clear
= f.label "Gender"
= f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']],
:first, :last,
:item_wrapper_class => 'horizontal',
) do |gender|
= gender.label { image_tag("/assets/icons/16x16/#{gender.text}.png") + gender.radio_button }
.clear
.ruler
回答1:
To remove the 2s and get the text label in there on the right use:
= f.label "Gender"
= f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']],
:first, :last,
:item_wrapper_class => 'horizontal',
) { |gender| gender.label { image_tag("/assets/icons/16x16/#{gender.text}.png") + gender.radio_button + gender.text } }
Removing the = before the gender.label will remove the 2s.
回答2:
Rubytastic you have an extra comma in your answer. Here is the correct code that @23inhouse was suggesting. It works for me in
- rails 3.1.3
- simple form 2.0.2
- haml 3.1.4
- haml-rails 0.3.4
= simple_form_for @object_new do |f|
.clear
= f.label "Gender"
- f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']], :first, :last, :item_wrapper_class => 'horizontal') do |gender|
= gender.label { image_tag("rails.png") + gender.radio_button }
.clear
.ruler
回答3:
Final working snippet:
= f.label "Gender"
- f.collection_radio_buttons(:gender, [['Male', 'icon_male'], ['Female', 'icon_female']], :first, :last, :item_wrapper_class => 'horizontal') do |gender|
= gender.label { image_tag("/assets/icons/16x16/#{gender.text}.png") + gender.radio_button }
.clear
.ruler
来源:https://stackoverflow.com/questions/11272764/simple-form-render-radio-button-group-with-image-x-label-with-twitter-boot