I would like to add the number_field form helper that exists in rails 3 to my rails 2.3.15 app, but i'm having trouble extending the module.
These are the methods I need from rails 3
class InstanceTag
def to_number_field_tag(field_type, options = {})
options = options.stringify_keys
if range = options.delete("in") || options.delete("within")
options.update("min" => range.min, "max" => range.max)
end
to_input_field_tag(field_type, options)
end
end
def number_field(object_name, method, options = {})
InstanceTag.new(object_name, method, self, options.delete(:object)).to_number_field_tag("number", options)
end
def number_field_tag(name, value = nil, options = {})
options = options.stringify_keys
options["type"] ||= "number"
if range = options.delete("in") || options.delete("within")
options.update("min" => range.min, "max" => range.max)
end
text_field_tag(name, value, options)
end
I'm adding this to a module which i include in my application helper. The to_number_field_tag
method is easy because i can just open the class and add the override.
The FormHelper module methods I'm having trouble with because i can't quite figure out the ancestors chain and don't know how to scope my override. I don't know how to make it work basically.