Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DidYouMean suggestions for missing templates #41845

Merged
merged 1 commit into from
Apr 8, 2021

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Apr 5, 2021

@seejohnrun and I wrote this together on his Twitch stream a few months ago, and it took me forever to actually submit. Oops! 馃槄

This PR adds DidYouMean spelling suggestions on MissingTemplate errors.

Missing partial test/_partail with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.

Searched in:
  * "/Users/jhawthorn/src/rails/actionview/test/fixtures"

Did you mean?  test/_partial
               test/_partialhtml
               test/_partial_only
               test/_partial_iteration_1
               test/_partial_iteration_2
               test/_partial_with_layout

We tried to do this efficiently, knowing that many applications have thousands of templates. Our approach was to match prefixes separately from names (ie. with users/_form we'd score users and _form separately). Since we have multiple prefixes we're searching for (the inheritance chain of the controller) this reduces the amount of scoring we have to do. We also able to reuse scoring of the template names because action names are commonly reused (show, edit, etc.). To combine the two scores we add them together, which isn't necessarily "correct", but experimentally it provided the matches we hoped for.

In the case that there is a template which matches by virtual_path but we got a MissingTemplate for another reason (probably details not matching) we don't provide suggestions. In the future I'd like to add suggestions for mismatched details as well.

@rails-bot rails-bot bot added the actionview label Apr 5, 2021
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
@jhawthorn jhawthorn merged commit 8096666 into rails:main Apr 8, 2021
@jhawthorn jhawthorn deleted the template_suggestions branch April 8, 2021 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants