Created
December 16, 2012 00:20
-
-
Save anonymous/4301317 to your computer and use it in GitHub Desktop.
Accept namespaced custom inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Formtastic | |
module Helpers | |
module InputHelper | |
# See: https://github.com/justinfrench/formtastic/issues/796 | |
def input_class_with_const_defined(as) | |
input_class_name = custom_input_class_name(as) | |
# get the parent module | |
module_class_name = input_class_name.deconstantize | |
module_class = module_class_name.blank? ? ::Object : module_class_name.constantize | |
# the input class name without the module part | |
input_class_name_wo_module = input_class_name.demodulize | |
if module_class.const_defined?(input_class_name_wo_module) | |
input_class_name.constantize | |
elsif Formtastic::Inputs.const_defined?(input_class_name) | |
standard_input_class_name(as).constantize | |
else | |
raise Formtastic::UnknownInputError, "Unable to find input class #{input_class_name}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment