1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Extract input_checked? to a module

This commit is contained in:
Rafael Mendonça França 2012-01-17 18:52:48 -03:00
parent 8b4c74f77c
commit 6f1bf526d7
4 changed files with 24 additions and 9 deletions

View file

@ -48,15 +48,6 @@ module ActionView
nil
end
def input_checked?(object, options)
if options.has_key?("checked")
checked = options.delete "checked"
checked == true || checked == "checked"
else
checked?(value(object))
end
end
def retrieve_autoindex(pre_match)
object = self.object || @template_object.instance_variable_get("@#{pre_match}")
if object && object.respond_to?(:to_param)

View file

@ -1,7 +1,11 @@
require 'action_view/helpers/tags/checkable'
module ActionView
module Helpers
module Tags
class CheckBox < Base #:nodoc:
include Checkable
def initialize(object_name, method_name, template_object, checked_value, unchecked_value, options)
@checked_value = checked_value
@unchecked_value = unchecked_value

View file

@ -0,0 +1,16 @@
module ActionView
module Helpers
module Tags
module Checkable
def input_checked?(object, options)
if options.has_key?("checked")
checked = options.delete "checked"
checked == true || checked == "checked"
else
checked?(value(object))
end
end
end
end
end
end

View file

@ -1,7 +1,11 @@
require 'action_view/helpers/tags/checkable'
module ActionView
module Helpers
module Tags
class RadioButton < Base #:nodoc:
include Checkable
def initialize(object_name, method_name, template_object, tag_value, options)
@tag_value = tag_value
super(object_name, method_name, template_object, options)