simple_form's collection_radio_button and custom label class

前端 未结 2 697
北恋
北恋 2020-12-30 12:26

I\'m trying to make a star rating form with radio collection using FontAwesome, for this I actually need to change the label classes of the collection_radio_button input gen

2条回答
  •  半阙折子戏
    2020-12-30 13:07

    This can be achieved by using a block:

    form_for @user do |f|
      f.collection_radio_buttons :rating, [[1, 'Bad'] ,[2, 'Ok'], [3, 'Great']],
                                 :first, :last, { item_wrapper_tag: false } do |b|
        b.radio_button + b.label(:class => "collection_radio_buttons icon-star")
      end
    end
    

    This doc can showcase some other example: http://rubydoc.info/github/plataformatec/simple_form/SimpleForm/FormBuilder:collection_radio_buttons

提交回复
热议问题