In old versions of Rails, we would rely entirely on what was returned by
Dir.glob to determine the match and sorting of our templates.
Later we switched to building a regex on each search, which allowed us
to perform a much faster glob, find matching templates with the regex,
and then emulate the sort order based on captures from the regex.
Now we have PathParser, which can parse any template's details
accurately from just its filename (not depending on the query being
made).
This commit moves the matching to done on UnboundTemplates, effectively
using details found by the PathParser for both matching and sorting of
templates, and removing the dynamic regex for queries.
This should be faster at boot/after reloads as we're no longer building
a regex and additionally we only need to parse a template's path for
details one time (we can use the same details for matching/sorting in
future queries with different details).
Previously, it was possible for these not to match due to providing
templates with .'s or using fallback templates.
There is now an exact 1:1 between templates on disk and virtual path.
Previously we just stored handler, format, and variant and assigned a
default format if none existed.
Now we want to also store locale, and move the default format behaviour
into unbound template.
Previously we would check that our paths were safe and inside the app
right before building templates. Instead we can do this, and reject
directories at the same time as we perform the glob.
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
Before this change did_you_mean shows partial paths like `animals/_partial`,
but adding that to your render call in a view like `<%= render 'animals/_partial' %>`
will still be missing as rails will search for the template `animals/__partial`.
We can provide the user a easier copy/paste correction if we don't tell them about the underscore.
This also reduces the candidates to only return partials if you are
looking for a partial and only look for non-templates when you are not
looking for a template.
This updates ActionView::CacheExpiry to hold a lock while inside the
executor (ie. inside a request) and to only clear caches when that is
done.
This is done using Concurrent::ReadWriteLock. This allows any number
of parallel requests to hold the read lock, but once we detect a change
and begin to acquire the write lock, all future requests will be
blocked.
This switches wildcard dependencies from using its custom
find_all_with_query method to use all_template_paths, the same method
now used for DidYouMean template suggestions.
This also removes related cache for wildcard queries. Since it was only
used during digesting, the digest cache should be sufficient.
This removes FallbackFileSystemResolver, LookupContext#with_fallbacks,
and LookupContext.fallbacks.
These used to exist to support `render file:`, and rendering templates
outside of the defined view paths. `render file:` has since been changed
to not use template resolution, and to only render absolute paths.
These were no longer callable through any public API.
This reverts commit d2f4541f126001e029078cc48a3a481e23ae3ed9.
It should work without curly braces.
See also: #41198, #41206, 81d90d81d0ee1fc1a649ab705119a71f2d04c8a2.
Keyword argument warnings are caused by #41206 to allow both
`current_page?(url_hash)` and `current_page?(**url_hash)` on Ruby 3.0.
Unfortunately it is super hard to support that for both Ruby 2.7 and 3.0
with the same method signature.
Closes#41710.
Prior to this change, javascript_include_tag was sending a hint using
rel="preload" for all scripts, including those of type="module".
This causes the browser to make a request to preload the script, but
because the rel is incorrect, it won't be able to reuse it.
When passing type="module", it should use rel=modulepreload instead.
[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
* Check for the presence of `formmethod` first before checking against
the GET/POST verbs;
* Use `match?` to avoid creating unnecessary match objects;
* Remove capture groups from the verb regexp.
Passing instance variables to `render` will be deprecated in the next
version, which is Rails 7.1.
Also add the non-deprecated implementation, which removes `@?` from the
Regexp, to make removal of the deprecation easier.
Rails partial rendering allows assigning instance variables.
For example:
render 'partial', :@name => "Maceo"
This sets @name to "Maceo" on the ActionView::Base object.
The allowed instance variables aren't restricted to the user's defined
instance variables but can also override private Rails variables like
@_assigns, @output_buffer, @_config, and @_default_form_builder.