Skip to content

Commit 2f078aa

Browse files
committed
Migrate DidYouMean.correct_error to DidYouMean::Correctable for MissingTemplate
Follow up to rails#42333.
1 parent 4121014 commit 2f078aa

File tree

1 file changed

+6
-14
lines changed
  • actionview/lib/action_view/template

1 file changed

+6
-14
lines changed

actionview/lib/action_view/template/error.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def initialize(paths, path, prefixes, partial, details, *)
5353
super out
5454
end
5555

56-
class Correction
56+
if defined?(DidYouMean::Correctable) && defined?(DidYouMean::Jaro)
57+
include DidYouMean::Correctable
58+
5759
Result = Struct.new(:path, :score)
5860

5961
class Results
@@ -83,20 +85,14 @@ def add(path, score)
8385
end
8486
end
8587

86-
def initialize(error)
87-
@error = error
88-
end
89-
9088
# Apps may have thousands of candidate templates so we attempt to
9189
# generate the suggestions as efficiently as possible.
9290
# First we split templates into prefixes and basenames, so that those can
9391
# be matched separately.
9492
def corrections
95-
path = @error.path
96-
prefixes = @error.prefixes
93+
candidates = paths.flat_map(&:all_template_paths).uniq
9794

98-
candidates = @error.paths.flat_map(&:all_template_paths).uniq
99-
if @error.partial
95+
if partial
10096
candidates.select!(&:partial?)
10197
else
10298
candidates.reject!(&:partial?)
@@ -141,17 +137,13 @@ def corrections
141137
end
142138
end
143139

144-
if @error.partial
140+
if partial
145141
results.to_a.map { |res| res.sub(%r{_([^/]+)\z}, "\\1") }
146142
else
147143
results.to_a
148144
end
149145
end
150146
end
151-
152-
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
153-
DidYouMean.correct_error(self, Correction)
154-
end
155147
end
156148

157149
class Template

0 commit comments

Comments
 (0)