如何将包装类添加到simple_form自定义集合中

时间:2013-04-01 08:16:25

标签: ruby-on-rails ruby-on-rails-3 simple-form

我已经创建了一个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

0 个答案:

没有答案