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

[「はい」、「いいえ」]を出力するだけです

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 に答える