From 176e52f13996a1a08249e3b07323c7be5f85f7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 9 Dec 2009 16:06:59 -0200 Subject: [PATCH] Move collection_radio to its own place. --- lib/simple_form.rb | 3 +++ lib/simple_form/builder_extensions.rb | 15 +++++++++++++++ lib/simple_form/input.rb | 10 ---------- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 lib/simple_form/builder_extensions.rb diff --git a/lib/simple_form.rb b/lib/simple_form.rb index c6042ff4..232e68d1 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -1,2 +1,5 @@ +require 'simple_form/builder_extensions' require 'simple_form/form_helper' require 'simple_form/form_builder' + +ActionView::Helpers::FormBuilder.send :include, SimpleForm::BuilderExtensions \ No newline at end of file diff --git a/lib/simple_form/builder_extensions.rb b/lib/simple_form/builder_extensions.rb new file mode 100644 index 00000000..d8c4d0cd --- /dev/null +++ b/lib/simple_form/builder_extensions.rb @@ -0,0 +1,15 @@ +module SimpleForm + # A collection of methods required by simple_form but added to rails default form. + # This means that you can use such methods outside simple_form context. + module BuilderExtensions + def collection_radio(attribute, collection, value_method, text_method, html_options={}) + collection.inject('') do |result, item| + value = item.send value_method + text = item.send text_method + + result << radio_button(attribute, value, html_options) << + label("#{attribute}_#{value}", text, :class => "radio") + end + end + end +end \ No newline at end of file diff --git a/lib/simple_form/input.rb b/lib/simple_form/input.rb index 2018523d..fc070026 100644 --- a/lib/simple_form/input.rb +++ b/lib/simple_form/input.rb @@ -53,15 +53,5 @@ module SimpleForm end end - def collection_radio(attribute, collection, value_method, text_method, html_options={}) - collection.inject('') do |result, item| - value = item.send value_method - text = item.send text_method - - result << radio_button(attribute, value, html_options) << - label("#{attribute}_#{value}", text, :class => "radio") - end - end - end end