Instead of treating it as an anonymous block, execute the
`ActionView::Base.field_error_proc` within the context of the
`ActionView::Base` instance.
This enables consumer applications to continue to override the proc as
they see fit, but frees them from declaring templating logic within a
`config/initializers/*.rb`, `config/environments/*.rb` or
`config/application.rb` file.
This makes it possible to replace something like:
```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
<<~HTML.html_safe
#{html_tag}
<span class="errors">#{instance.error_message.to_sentence}</span>
HTML
end
```
With inline calls to Action View helpers like:
```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
safe_join [ html_tag, tag.span(instance.error_message.to_sentence, class: "errors") ]
end
```
Or with a view partial rendering, like:
```ruby
config.action_view.field_error_proc = proc do |html_tag, instance|
render partial: "application/field_with_errors", locals: { html_tag: html_tag, instance: instance }
end
```
Then, elsewhere in `app/views/application/field_with_errors.html.erb`:
```erb
<%= html_tag %>
<span class="errors"><%= instance.error_message.to_sentence %></span>
```
Infer HTTP verb `[method]` from a model or Array with model as the first
argument to `button_to` when combined with a block:
```ruby
button_to(Workshop.find(1)){ "Update" }
#=> <form method="post" action="/workshops/1" class="button_to">
#=> <input type="hidden" name="_method" value="patch" autocomplete="off" />
#=> <button type="submit">Update</button>
#=> </form>
button_to([ Workshop.find(1), Session.find(1) ]) { "Update" }
#=> <form method="post" action="/workshops/1/sessions/1" class="button_to">
#=> <input type="hidden" name="_method" value="patch" autocomplete="off" />
#=> <button type="submit">Update</button>
#=> </form>
```
Prior to this change, the constructed `<form>` was always submitted with
a `[method="post"]` and _always_ omitted the `<input type="hidden"
name="_method" value="...">` field, regardless of the return value of
the "model" argument's `#persisted?` predicate.
It's `Rails.application.executor.wrap` that is responsible for
clearing request/job local state such as `CurrentAttributes`.
Instead of including an ad hoc helper to clear `CurrentAttributes` it's
better to run the executor so we properly clear other states as well.
However it means all executor hooks now need to be re-entrant.
This module will be a private module in Active Support, this way
if we need to change the behavior of translate in controllers or
views don't forget to change in the other one.
* Make Sprockets more optional, offer Propshaft as alternative
* Whups, local reference
* No longer used
* Spacing
* Need explicit sprockets-rails inclusion now
* Manually require the sprockets railtie
* Don't need these changes right now
* Kick off another build
* Fix tests
* DRY up test
* Require railtie when using sprockets
* Introduce option to skip asset pipeline
* No longer relevant
* Always have to return
* Gone
* Add helper for skip_sprockets?
* Fix guard statement
* Use latest gems
* Include propshaft
* fix tests for #43261 (#43277)
* help fix tests for #43261
skip_sprockets? should not be called on options
:skip_sprockets is no longer a value in the option hash, so
skip_sprockets? should not be called on it
move --asset-pipeline to shared generator
skip_sprockets? is defined on app_base, and used in the plugin
generator to determine whether to add the engine's assets to the dummy
sprockets manifest, so I believe it makes sense to include in both
generators
Because of this change, I also changed the shared test back to testing
against non-sprockets
add skip_sprockets to Gemfile template vars
Mocking skip_sprockets? in app_base generator
fix more generator tests
* use skip_sprockets? everywhere
* Use latest propshaft
* Update `AssetUrlHelper` docs to list both asset pipeline gems (#43328)
* Update to latest Propshaft
* Bump Propshaft again
* Ask for latest
* Use latest propshaft
Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Richard Macklin <1863540+rmacklin@users.noreply.github.com>
The word "Crazy" has long been associated with mental illness. While
there may be other dictionary definitions, it's difficult for some of us
to separate the word from the stigmatization, gaslighting, and bullying
that often comes along with it.
This commit replaces instances of the word with various alternatives. I
find most of these more focused and descriptive than what we had before.
The ActionView::Helpers::Tags::CheckBox class accepts the `checked` and `include_hidden` options. The documentation for these options is added to the `check_box` methods in the ActionView::Helpers::FormHelper class where they are exposed.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
Change `begin_on_monday` to `beginning_of_week`
Change `begin_on_monday` to `beginning_of_week`
Better handle ignored day
Remove inaccurate tests
Improve docs and use DAYS_INTO_WEEK to calc rotation
Remove inaccurate docs
Use Kernel::Float(..., exceptions:false) instead of a rescue block in
ActionView::Helpers::NumberHelper and
ActiveSupport::NumberHelper::NumberConverter to slightly improve
performance.
Also remove documentation that incorrectly states
ActiveSupport::NumberHelper supports the `raise:` option.
Swaps to case/when to highlight the 3 branches better and uses `presence_in`
to cut down on the else branch noise.
`resolve_link_as` added in: eb90b8bc86e758045a707cae43d11dab538ca6db
Most recent other commit: 46bfd082b00a6c10f7263c769edb9c053bd03936
Made a decision to tweak this as core, don't send cosmetic PRs.
I found an unexpected use of assertion in the block of `assert_raise`
when I implemented https://github.com/rubocop/rubocop-minitest/pull/137.
It is expected to be asserted after an exception is raised in
`assert_raise` block, but in actually it is not asserted after an
exception is raised. Therefore, this PR removes or updates assertions
that have not been asserted after an exception has raised.
This PR will add `rubocop-minitest` and enable
`Minitest/UnreachableAssertion` cop to able similar auto-detection,
but will remove `rubocop-minitest` from this PR if you don't like it.
Add `weekday_select` method
Create `Tags::WeekdaySelect` class
Add `weekday_select` to `FromBuilder`
Add Documentation
Allow `WeekdaySelect` to use selected option if value is nil
Doc fix
Add tests
Use kwrd args
Update CHANGELOG
Fix `Tags::WeekdaySelect` for updated kwrd args
Update CHANGELOG format
Condense `weekday_options_for_select` method
Update tests for kwargs
This leaves Ripper tracker as an optional view dependency tracker, but uses the current ERBTracker by default.
Eventually the default can change to the Ripper tracker, but this makes it an optional update for now
Caching something that shouldn't be cached is a potential source of
bugs and security vulnerabilities. For example, one could write a
form helper that outputs a request-specific auth token, only for
the helper to be used inside of a `cache` block.
In the GitHub application, we implemented a caching? method and used
it to raise an error if a specific code path is being cached that
we don't want to be cached.
I've credited its original author, @btoews.
Co-authored-by: Ben Toews <mastahyeti@gmail.com>
Co-authored-by: John Hawthorn <jhawthorn@github.com>
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
* Update resolve_link_as to include SVG
Preloading SVGs won't work without 'as: image' because of:
`Preload of /packs/media/images/81d035675e31079ea9da.svg was ignored due to unknown “as” or “type” values, or non-matching “media” attribute.`
Preloading SVGs can be useful, for instance when using sprites such as bootstrap-icons.
* Adds test case for asset_tag_helper
* Fix test case -- silly mistake
[xanderificnl + Rafael Mendonça França]
This fixes the `current_page?` helper when the given URL has a trailing
slash, and is an absolute URL or also has query params.
Fixes#33956.
Co-authored-by: Rien Maertens <rien.maertens@posteo.be>
As a follow-up to [#40127][], this commit adds a bug fix for nested form
builders (through either `fields_for` or `fields`) incorrectly
constructing a field's `[id]` attribute. To do so, treat the
`@object_name` with higher precedence than the `@object`, since that
will be provided as instance state during construction.
[#40127]: https://github.com/rails/rails/pull/40127
Instead of using the ERBTracker, we can use RipperTracker which is extracted from https://github.com/jhawthorn/actionview_precompiler.
Using a parser finds dependencies that would otherwise be difficult to find with the regular expressions. It should also theoretically work with other template systems since it operates on the compiled template instead of the contents of the file.
Co-authored-by: John Hawthorn <john@hawthorn.email>
As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
need to check if DidYouMean is defined in the test suite. We still need
to check if the DidYouMean modules are defined in the actual code, as
someone might run Rails with DidYouMean disabled by using the
`--disable-did_you_mean` flag. This is ussually done for performance
reasons.
This commit also includes some of the changes made by Yuki in:
https://github.com/rails/rails/pull/39555
These changes include replacing Jaro with the more accurate
SpellChecker, and using DidYouMean::Correctable for simplere
corrections.
The DidYouMean::SpellChecker does have a treshold for corrections.
If there is not enough similarity it might not return a suggestion.
To stop the tests from failing some test data had to be changed.
For example, `non_existent` does not meet the treshold for `hello`, but
`ello` does:
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
=> []
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
=> ["hello"]
The treshold makes sense for spelling errors. But maybe we should add a
different SpellChecker that helps to get a suggestion even if there is
little overlap. For example for when a model only has 2 attributes
(title and body), it's helpful to get a suggestion for `name`
Co-Authored-By: Yuki Nishijima <yk.nishijima@gmail.com>
* Don't attach UJS form submission handlers to Turbo forms
Allows for easier migration of apps written for UJS, such that new work can be done with Turbo forms that are marked with data-turbo=true.
* Fix duplicate selectors
* Proper fix take 2
Both methods are defined in multiple parts of the framework. It would
be useful to put them in a proper place, so that repetition is
avoided.
I chose the implementation from `ActiveRecord` because it's a bit more
complete with the `SQLCounter` class, and also because other parts
depend on it.
before https://github.com/rails/rails/pull/40125 test names would be
set to "test" after this change controller_name was nil when using
ActionView::TestCase.
This returns ActionView::TestCase to previous behavior returning "test"
Add failing test for views with trailing newlines
Add and test config option
Move config option to config/application.rb
Move implementation to ERB template handler
Move config option to ActionView::Template::Handlers::ERB
When dealing with the "details" for a template: locale, format,
variant, and handler, previously we would store these in an ad-hoc way
every place we did. Often as a hash or as separate instance variables on
a class.
This PR attempts to simplify this by encapsulating known details on a
template in a new ActionView::TemplateDetails class, and requested
details in ActionView::TemplateDetails::Requested.
This allowed extracting and simplifying filtering and sorting logic from
the Resolver class as well as extracting default format logic from
UnboundTemplate.
As well as reducing complexity, in the future this should make it
possible to provide suggestions on missing template errors due to
mismatched details, and might allow improved performance.
At least for now these new classes are private (:nodoc)
Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>