我创建了一个 SimpleForm 自定义输入,并且还想根据其值将类名添加到某个项目的包装元素,以便通过 CSS 装饰该项目。但我不知道如何访问每个项目的价值。请参考我下面的代码:
class ProductOptionInput < SimpleForm::Inputs::CollectionRadioButtonsInput
def input
label_method, value_method = detect_collection_methods
@builder.send("collection_radio_buttons",
attribute_name, collection, value_method, label_method,
input_options, input_html_options, &collection_block_for_nested_boolean_style
)
end
def build_nested_boolean_style_item_tag(collection_builder)
template.shirt_option_icon(attribute_name, collection_builder.value) + \
collection_builder.radio_button + \
template.content_tag(:div, collection_builder.text, class: :name)
end
def item_wrapper_class
classes = super
classes << ' highlight' if @builder.object.product.send(attribute_name) == [current item's value]
classes
end
end