如何在简单表单中的每个单选按钮之前添加标记?

简单的必要性,但显然没有简单的方法来使用Simple Form。

我需要在使用Simple表单的Rails表单中的每个无线电input之前放置一个span 。 我已按照本指南的说明成功地为文本输入添加了一个span ,但我无法弄清楚如何使用单选按钮(以及复选框)执行相同的操作。

我不想使用jQuery,我目前正在使用它作为一种解决方法。


更新1

正如@TarynEast在评论中提到的那样,我尝试使用以下代码创建初始化程序,我已经能够将span标记添加到字符串input

初始化

 # config/initializers/simple_form__spanner class SpannerInput < SimpleForm::Inputs::Base def input(wrapper_options) merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) spanner_input = "" spanner_input << @builder.text_field(attribute_name,merged_input_options) return spanner_input.html_safe end end 

视图

 # the view code  

HTML输出

 # the output in view 

现在我希望能够用单选按钮和复选框做同样的事情。 输出应该是这样的:

    

更新2

(几乎是解决方案)

我有一些东西可以以某种方式做我想要的,即在一组单选按钮或复选框中每个输入有一个span 。 它在input标签之后输出跨度,但在文本之前输出它有点起作用。

该解决方案不会使用任何初始化程序,它只是为集合中的每个对象运行的lambda

假设你有一个调用choices的数组:

 choices = [ { label: "Foo", value: "foo" }, { label: "Bar", value: "bar" } ] 

视图

 # the view code  (choice){ "#{ choice[:label] }".html_safe } %> 

产量