0

我在这里做错了什么:

def radio_button(label, *args)
  options = args.extract_options!
  collection = options[:collection]
  options.delete :collection
  # put back into args to pass to super
  args << options

  collection.each do |item|
    label(label, class: "radio-inline") do
      super(label, item, *args) do
        item.to_s.humanize
      end
    end          
  end
end

我打电话给它

= f.radio_button :receiving_treatment, collection: ["yes", "no"], required: true

它只是输出 ["yes", "no"]

4

1 回答 1

0

这是我解决它的方法。我找到了新方法 collection_radio_buttons 并用它来构建我的 formbuilder 方法。

现在我打电话给:

= f.yes_no_radio_buttons :receiving_treatment, required: true

我的表单生成器有:

  def yes_no_radio_buttons(method, *args)
    collection_radio_buttons(method, ["yes", "no"], :to_s, "humanize", *args)
  end

  def collection_radio_buttons(method, collection, value_method, text_method, *args)
    super(method, collection, value_method, text_method, *args) do |b|
      b.label(class: "radio-inline") { b.radio_button(*args) + b.text }
    end
  end
于 2013-09-23T10:46:49.587 回答