From ae12516978a07b75bb3f929829170b7f5716f53c Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 14 May 2024 17:25:31 -0300 Subject: [PATCH] Revert "Merge pull request #1810 from meanphil/mappings-slow-exception" This reverts commit b6ae67d28599b3c676b670e23e478063aba14cf6, reversing changes made to 0ef4a58daae41ab091d25ac1dc3fb4ede35743b1. This caused custom inputs to not load properly on non-eager load environments like dev/test, because those constants may not have been defined yet. The previous code would try to constantize them and force-load the lazily-loaded files/constants, the new code breaks that behavior, so we're reverting. Closes #1824, see for more info. --- CHANGELOG.md | 1 + lib/simple_form/form_builder.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb32b4ca..64ec3c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Unreleased +* Revert "Speed up input mapping lookup by avoiding rescuing exceptions" from v5.3.0, it caused a regression on dev/test environments with custom inputs. * Add support to Ruby 3.3. (no changes required.) ## 5.3.0 diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index a5cb4c14..da723cb7 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -673,7 +673,11 @@ def mapping_override(klass) def attempt_mapping(mapping, at) return if SimpleForm.inputs_discovery == false && at == Object - at.const_get(mapping) if at.const_defined?(mapping) + begin + at.const_get(mapping) + rescue NameError => e + raise if e.message !~ /#{mapping}$/ + end end def attempt_mapping_with_custom_namespace(input_name)