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:
parent
8b4c74f77c
commit
6f1bf526d7
4 changed files with 24 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
16
actionpack/lib/action_view/helpers/tags/checkable.rb
Normal file
16
actionpack/lib/action_view/helpers/tags/checkable.rb
Normal 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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue