Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2012 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4301317 to your computer and use it in GitHub Desktop.
Save anonymous/4301317 to your computer and use it in GitHub Desktop.
Accept namespaced custom inputs
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