simple_form render radio button group with <image>( X ) Label with twitter bootstrap?

落花浮王杯 提交于 2019-11-30 04:35:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!