Commit Graph

1253 Commits

Author SHA1 Message Date
Wojciech Wnętrzak 2dea9aebf2
Add include_seconds option to datetime_local_field.
This allows to omit seconds part in the input field, by passing `include_seconds: false`

It's a follow up to https://github.com/rails/rails/pull/41728
2022-07-06 22:27:04 +02:00
eileencodes 9766eb4a83
Fix tests for minitest 5.16
In minitest/minitest@6e06ac9 minitest changed such that it now accepts
`kwargs` instead of requiring kwargs to be shoved into the args array.
This is a good change but required some updates to our test code to get
the new version of minitest passing.

Changes are as follows:

1) Lock minitest to 5.15 for Ruby 2.7. We don't love this change but
it's pretty difficult to get 2.7 and 3.0 to play nicely together with
the new kwargs changes. Dropping 2.7 support isn't an option right
now for Rails. This is safe because all of the code changes here are
internal methods to Rails like assert_called_with. Applications
shouldn't be consuming them as they are no-doc'd.
2) Update the `assert_called_with` method to take any kwargs but also
the returns kwarg.
3) Update callers of `assert_called_with` to move the kwargs outside the
args array.
4) Update the message from marshaled exceptions. In 5.16 the exception
message is "result not reported" instead of "Wrapped undumpable
exception".

Co-authored-by: Matthew Draper <matthew@trebex.net>
2022-06-23 08:32:11 -04:00
John Crepezzi df0de681dc Remove the multi-call form of assert_called_with
The `assert_called_with` helper allows passing a multi-dimensional array to
mock multiple calls to the same method for a given block. This works
fine now, but when adding support for real kwargs arguments to line up with
recent upgrades in Minitest, this approach is no longer workable because
we can't pass multiple sets of differing kwargs.

Rather than complicated this method further, this commit removes the
multi-call form of `assert_called_with` and modifies the tests that
currently make use of that functionality to just use the underlying
`Minitest::Mock` calls.

Co-authored-by: Eileen M. Uchitelle <eileencodes@gmail.com>
2022-06-16 11:13:57 -04:00
Sean Doyle 8a0bc4aa90 Support calls to `#field_name` with nil `object_name`
It's possible for `ActionView::Helpers::FormTagHelper#field_name` calls
made by instances constructed through `fields` and `fields_for` helpers
to have an `object_name` argument that's `nil`. For example, the
following will raise an `undefined method `empty?' for nil:NilClass`
exception:

```erb
<%= fields do |f| %>
  <%= f.field_name :body %>
<% end %>
```

To guard against those calls, replace the method's call to
`String#empty?` with `Object#blank?`, since `NilClass#empty?` is not
defined.
2022-06-15 18:51:20 +01:00
eileencodes 935120fdfd
Fix did you mean tests for ruby-trunk (3.2)
In
f075be3dcb
did_you_mean and error_highlight now use `detailed_message` over
`message` to display errors.

For cases where we are testing `message`, in 3.2 and above we need to
test against `detailed_message` instead.

As far as I can tell in a Rails console when these errors are raised the
`detailed_message` is used so we shouldn't need to make other changes to
Rails. The only case where this isn't true is in the Railties changes -
we are explicitly formatting the did you mean message so we need to be
sure to call `detailed_message` here.

This fixes most of the failing tests for ruby-trunk.
2022-06-10 13:06:42 -04:00
Mike Dalessio 5f8f6764d8
Strings returned from `strip_tags` are correctly tagged `html_safe?`
Because these strings contain no HTML elements and the basic entities
are escaped, they are safe to be included as-is as PCDATA in HTML
content. Tagging them as html-safe avoids double-escaping entities
when being concatenated to a SafeBuffer during rendering.

Fixes https://github.com/rails/rails-html-sanitizer/issues/124
2022-05-31 10:02:07 -04:00
John Hawthorn a5b2b6155c
Merge pull request #45169 from oneiros/allow_all_available_locales_for_template_lookup
Allow all available locales for template lookups
2022-05-30 11:49:40 -07:00
David Roetzel 12c12899df Allow all available locales for template lookups.
Following the discussion here:
https://github.com/rails/rails/pull/44174/files#r785160819

Background: The `i18n` gem is relatively lax when it comes
to naming locales. It does not enforce any standard. Thus
it is possible to have e.g. per tenant locales (think
`en_tenant1`, `en_tenant2` etc.). This also worked for
translated templates up until rails 6.1.

Rails 7 changed the template lookup and enforced a naming
scheme for locales. This poses a problem for legacy apps
that use non-standard locale names.

This commit changes the way locale names are detected in
template file names. In addition to the previously used
regexp it also allows all known locales from
`I18n.available_locales`.

This makes it backwards compatible to rails 7.0
behavior while also allowing non-standard locale names.
Thanks to jvillarejo for the great idea.

Also introduce the usage of `Regexp.union`, a wonderful
suggestion by casperisfine.
2022-05-30 09:45:28 +02:00
Sean Doyle 980de46f54 Move `convert_to_model` call from `form_for` to `form_with`
Ensure models passed to `form_with` attempt to call `to_model`.

Now that `form_for` is implemented in terms of `form_with`, this commit
also removes the `convert_to_model` call from the `form_for` implementation.

To exercise this behavior, change existing `form_with` test coverage.

Prior to this change, a call to `form_with` made with a `model:` argument
that responds to `to_model` would not incorporate the instance's persistence
state into the form's HTTP verb. After this change, the persistence state
inferred from the `model:` argument's `to_model` call is incorporated into
the `<form>` element's `[method]` attribute.

This is a separate follow-up change proposed in [rails/rails#44328][].
The original change to restore old behavior _deliberately_ excluded
applying the same logic to `form_with`, since it would be a breaking
change from how `form_with` behaved previously.

This commit proposed making that breaking change.

[rails/rails#44328]: https://github.com/rails/rails/pull/44328#discussion_r808475585
2022-05-25 09:48:58 -04:00
Jean Boussier dd0b302378
Merge pull request #45029 from jonathanhefner/fix-extract_dimensions-regexp
Escape literal dot in regular expression
2022-05-09 09:55:00 +02:00
Jonathan Hefner fe24f5880d Escape literal dot in regular expression
Follow-up to #44669.

This ensures that e.g. sizes with commas are not erroneously matched.
2022-05-05 14:08:43 -05:00
eileencodes 944bcb54f6
Fix tag helper regression
Vue.js, alpinejs, and potentially other JS libraries support tags
starting with `@` symbols. This was broken by the recent security release in
649516ce0f

I've only added `@` to the list even though there are potentially other
safe characters. We can add more if necessary (and if safe).

Fixes:
* #45014
* #44972
2022-05-05 10:42:41 -04:00
Alvaro Martin Fraguas 649516ce0f
Fix and add protections for XSS in names.
Add the method ERB::Util.xml_name_escape to escape dangerous characters
in names of tags and names of attributes, following the specification of
XML.

Use that method in the tag helpers of ActionView::Helpers. Rename the option
:escape_attributes to :escape, to simplify by applying the option to the whole
tag.
2022-04-26 12:34:42 -07:00
Xavier Noria 2953ae5c8a Define config.enable_reloading to be !config.cache_classes
Every time I write `config.cache_classes` I have to pause for a moment to make
sure I get it right. It makes you think.

On the other hand, if you read `config.enable_reloading = true`, does the
application reload? You do not need to spend 1 cycle of brain CPU to nod.
2022-04-14 18:11:36 +02:00
John Bampton ad91029117 Change `rss` to `RSS` in `ImageLinkToTag` 2022-04-01 12:05:28 +10:00
Aaron Patterson 8961b8ece7
Merge pull request #44669 from kaiquekandykoga/extract-float
Extract float
2022-03-14 15:16:06 -07:00
Kaíque Kandy Koga 16e6d77200 Extract float numbers when using size option
for image_tag and video_tag

Delete space

format_numbers number_formats

Add tests

Change tests

Use regex in extract_dimensations
2022-03-14 14:11:07 -03:00
Aaron Patterson d28efa55fa
Merge pull request #43975 from codergeek121/bugfix-for-time-select-prompt
Fix a bug with time_select and prompts
2022-03-14 09:44:42 -07:00
Dave Kroondyk 8d51706c20 Remove circle from HTML_VOID_ELEMENTS set.
`<circle>` is in the SVG_SELF_CLOSING_ELEMENTS list and is not a void element according to
'https://html.spec.whatwg.org/multipage/syntax.html#void-elements'.
2022-03-01 09:08:23 -05:00
Dave Kroondyk 3814826885 Ensure SVG elements are closed.
Changes introduced in https://github.com/rails/rails/pull/43232 break SVGs
that have mulitple of the same descendant tag because they weren't being
closed. SVG elements must be closed accodoring to spec
https://html.spec.whatwg.org/multipage/syntax.html#elements-2.

Fixes https://github.com/rails/rails/issues/44563
2022-02-28 17:52:02 -05:00
Clayton Smith 6e56e18523 Fix flaky Action View tests 2022-02-23 09:39:57 -05:00
Jean Boussier e26372b713 Implicitly assert no exception is raised in `assert_queries` & al
Fix: https://github.com/rails/rails/pull/44397
Ref: https://github.com/rails/rails/pull/37313
Ref: https://github.com/rails/rails/pull/42459

This avoid mistakes such as:

```ruby
assert_raise Something do
  assert_queries(1) do
    raise Something
  end
end
```

Co-Authored-By: Alex Coomans <alexc@squareup.com>
2022-02-19 09:11:14 +01:00
Sean Doyle 9dc083f95d `form_for`: Attempt to call `to_model` on record
Related to https://github.com/rails/rails/issues/44326

---

The changes introduced in [rails/rails#43421][] did not account for
attempting to coerce the record with [#to_model][]. This commit resolves
that issue and adds test coverage to guard against future regressions.

Additionally, this adds tests to exercise `form_with` to ensure that it
_does not_ call `#to_model` on its `model:` argument, since that was the
behavior in [6.1.4.4][]

[rails/rails#43421]: https://github.com/rails/rails/pull/43421
[#to_model]: https://edgeapi.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_model
[6.1.4.4]: https://github.com/rails/rails/issues/44326#issuecomment-1029344241
2022-02-17 16:01:57 -05:00
John Hawthorn 139ef8a0bc
Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex
Add support to locales with lowdash in Resolver::PathParser
2022-02-17 08:27:34 -08:00
Ryuta Kamizono 135f41d0b0
Merge pull request #44337 from paulhenri-l/patch-1
Fix empty request inside helpers test
2022-02-09 17:33:40 +09:00
Paul-Henri Leobon 867e60f6c2
Fix empty request inside helpers test
During testing view helpers do not have access to the `request` object but they do when used inside of a view.

If we were to test a helper like this one :

```ruby
  def active?(test_path)
    request.path.match? test_path
  end
```

we would get this error : 

```
NoMethodError: undefined method `path' for nil:NilClass
```

Adding `:request` to the attr_accessor will make tests consistent with the default behavior.
2022-02-09 08:47:27 +01:00
David Heinemeier Hansson 41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Jonathan Hefner 9648e89511 Fix test_tag_attributes_escapes_values assertion
The 1st argument to `assert_not_includes` is the collection to search;
the 2nd argument is the element to search for.  Thus this test was
checking if the output was included in the forbidden string, rather than
checking the if the forbidden string was included in the output.

Because negative assertions like this one can be fooled more easily,
this commit changes the test to use `assert_equal`, as the other tests
do.
2022-01-29 12:10:14 -06:00
Yasuo Honda d6f96a9d7c Address ActionView::Template::Error
This commit addresses the following CI error.
https://buildkite.com/rails/rails/builds/84207#3bc8eb7f-c86d-4f6f-8932-e2e8c26cf893

There were similar pull requests #36189 #39949

```ruby
$ bin/test test/template/test_case_test.rb test/template/render_test.rb -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598
Run options: -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598

.E

Error:
FrozenStringLiteralEnabledViewRenderTest#test_render_partial_collection_for_non_array:
ActionView::Template::Error: undefined method `__home_yahonda_src_github_com_rails_rails_actionview_test_fixtures_test__customer_erb__1256308179417979847_7880' for #<ActionView::Base:0x00000000003de0>
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `public_send'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `_run'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:157:in `block in render'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:208:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:361:in `instrument_render_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:155:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:189:in `block in collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `block in each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `yield'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `block in test_render_partial_collection_for_non_array'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `map'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:162:in `block (2 levels) in render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb:21:in `cache_collection_render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:161:in `block in render_collection'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `block in instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:147:in `render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:119:in `render_collection_with_partial'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:72:in `render_partial_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:27:in `render_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:22:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:38:in `block in render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:270:in `in_rendering_context'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:34:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:388:in `test_render_partial_collection_for_non_array'

bin/test test/template/render_test.rb:383

Finished in 0.047002s, 42.5514 runs/s, 63.8271 assertions/s.
2 runs, 3 assertions, 0 failures, 1 errors, 0 skips
$
```
2022-01-27 16:36:27 +09:00
Maximo Mussini dd870eef11 Ensure preload_link_tag preloads modules correctly
Prior to this change, preload_link_tag always used rel=preload

This causes the browser to make a request to preload the script, but
for modules scripts the rel does not match the type, so the browser
can not reuse the prefetched script and discards 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
[3] developers.google.com/web/updates/2017/12/modulepreload
2022-01-18 18:00:04 -03:00
Juan Guecaimburu bd0753b396 Add support to locales with lowdash in Resolver::PathParser
In previous versions of Rails, a dynamic regex was built to find templates.
After that, PathParser started to be used to both match and sort templates.
With the dynamic regex, templates with lowdash locales (es_AR) were
found properly. But the PathParser regex does not match locales with this
format, only allowing dash (es-AR) or no dash (es). Templates with lowdash
locales have a wrong virtual path and get filtered.

In this commit the PathParser regex is extended to support the lowdash.
2022-01-14 15:11:58 -03:00
Niklas Haeusele 46e2901f12 Fix a bug with time_select and prompts
Rendering a time_select like suggested here actionview/lib/action_view/helpers/date_helper.rb:317
does not actually show the default prompt but a prompt with textcontent "true".
Now it actually renders the default prompt in this case, like suggested
in the documentation.
2021-12-23 18:27:45 +01:00
Rafael Mendonça França dfd28646fe
Merge PR #43157
Add test for #43157

    fix test

    fix #43146

Co-Authered-By: qinmingyuan <mingyuan0715@foxmail.com>
2021-12-20 23:01:53 +00:00
Alex Ghiculescu da7ff04c69 Fix `link_to` with a model passed as an argument twice
Fixes https://github.com/rails/rails/issues/43913 which found a regression in https://github.com/rails/rails/pull/42234
2021-12-17 12:24:25 -06:00
Sean Doyle c6c138ef86 Generate `[id]` for `FormBuilder#button` called with method name
Follow-up to [rails/rails#43411][] (merged in [15f6113][])

By default, when generating a `<button>` element through a Form Builder
instance, the element's `[name]` attribute is populated by calling the
`FormBuilder#field_name` method. This commit assigns a matching default
`[id]` attribute generated by `FormBuilder#field_id`.

Additionally, it adds test coverage to ensure that calls that provide
their own `name:` and `id:` options are not overridden by the default
values.

[rails/rails#43411]: https://github.com/rails/rails/pull/43411
[15f6113]: 15f6113622
2021-12-15 17:49:28 -05:00
Rafael Mendonça França 68f4fbc7cf
Merge pull request #43850 from hachi8833/fix_favicon_link_tag
Remove "shortcut" link type from favicon_link_tag method
2021-12-14 20:37:34 -05:00
Sean Doyle 4f191b9754 ActiveStorage: support empty attachments submits
The background
---

Configuration for replacing a collection was introduced in
[rails/rails#36716][].

However, since [rails/rails#42596][] has been merged, Rails 7.1 and
beyond will default to _replacing_ an Active Storage `has_many_attached`
relationship, as opposed to _appending to it_.

The problem
---

With replacement as the established precedent, it's currently a
challenge to replace an existing collection with an empty one.

The solution
---

This commit makes two changes.

The first is to Action View and its form building helpers. The change
draws inspiration from how an `<input type="checkbox">` field (or
collection of fields) is paired with an `<input type="hidden">` field to
represent the unchecked value. The change pairs any `<input type="file"
multiple="multiple">` elements with an `<input type="hidden">` element
to represent an empty collection. Like the [check_box][] form builder
method, the `file_field`  method accepts an `include_hidden:` option to
skip the creation of the hidden element.

The second is to how Active Storage generates attribute assignment
methods through `has_many_attached`. With the possibility of an `<input
type="file">` field being paired with an `<input type="hidden"
value="">` field, the backing models need to be able to coerce an
"empty-ish" value into an empty list. For example:

```ruby
@user.highlights = [""]
@user.highlights        # => []
```

When combined, these changes enable consumer applications to submit
"empty" collections to blank out existing attachments.

Support is configured through the
`config.active_storage.multiple_file_field_include_hidden` configuration
value, which defaults to `false`.

[check_box]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box
[rails/rails#36716]: https://github.com/rails/rails/pull/36716
[rails/rails#42596]: https://github.com/rails/rails/pull/42596
2021-12-14 18:40:35 -05:00
Sean Doyle 0b8dde0078 FormBuilder#field_id: prepend `namespace:` option
When constructing the field's `[id]` attribute, the current
`FormBuilder#field_id` implementation (introduced in [59ca21c][])
ignores the `namespace:` option.

This commit incorporates any namespace by prepending it to the
`@object_name`.

[59ca21c]: 59ca21c011

Re-use template.field_id
---

Thread options[:namespace] down through the FormBuilder instance to the
`Tags::Base#tag_id` and `#add_default_name_and_id` methods
2021-12-14 18:00:01 -05:00
Pedro Moreira 3edada28fa
Fix rubocop issue of single- vs double- quotes (+1 squashed commit)
Squashed commits:
[49cb03a3ce] Fix missing return from ActionView::Helpers::NumberHelper#parse_float, fixes #43853
Add test case for number helpers not raising exception when `raise: true` is passed and input is valid
2021-12-13 16:48:53 +00:00
hachi8833 240c1ace76 Remove "shortcut" link type from favicon_link_tag method
Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types
Ref: https://mathiasbynens.be/notes/rel-shortcut-icon

Update layout.html.erb for Guides

Remove "shortcut" from welcome page
2021-12-13 13:49:43 +09:00
Rafael Mendonça França 7160f46a9e
Merge pull request #43368 from FestaLab/render-hash-syntax
Replaces the hash rocket operator in favor of the newer Ruby syntax on render
2021-12-08 18:13:44 -05:00
Rafael Mendonça França c2e12e0191
Use `to_formatted_s(:db)` instead of `to_s(:db)` internally
Ruby 3.1 introduced an optimization to string interpolation for some
core classes in b08dacfea3.

But since we override `to_s` in some of those core classes to add behavior
like `to_s(:db)`, all Rails applications will not be able to take advantage
of that improvement.

Since we can use the `to_formatted_s` alias for the Rails specific behavior
it is best for us to deprecate the `to_s` core extension and allow Rails
applications to get the proformace improvement.

This commit starts removing all the `to_s(:db)` calls inside the framework
so we can deprecate the core extension in the next commit.
2021-12-06 19:22:04 +00:00
Zhongying Qiao c92ac83fe6
In #4342, part of the functionalities of form_for was delegated to form_with, this could potentially cause some regress, as the condition to send polymorphic_path(record, {}) instead of polymorphic_path(record, format: options.delete(:format)) is removed and when format is not passed, this causes issues if the caller is not expecting an extra arg format:nil. This PR adds back the condition inside for with and add a test to make sure it doesn't break for_with 2021-12-02 13:29:38 -08:00
Jean Boussier 6dc9e3309f Action View: allow to compile ERB templates with `# frozen_string_literal: true`
This can save a significant amount of string allocation in some scenarios
and is more consistent with modern Ruby code where `frozen_string_literal`
is enabled most of the time.
2021-11-29 10:38:51 +01:00
Rafael Mendonça França 884c97fad0
Remove deprecated support concat errors to `ActiveModel::Errors#messages` 2021-11-17 21:51:25 +00:00
Rafael Mendonça França d4ad739454
Remove deprecated `Rails.config.action_view.raise_on_missing_translations` 2021-11-17 21:51:16 +00:00
Rafael Mendonça França 846f9e9595
Merge PR #43416 2021-11-15 22:55:37 +00:00
Rafael Mendonça França 033822117b
Merge PR #43413 2021-11-15 22:35:01 +00:00
Sean Doyle 15f6113622 Support name Symbol to `FormBuilder#button`
Since `<button>` elements translate their `[name]` and `[value]`
attributes to the resulting `<form>` element submission, and are encoded
into the resulting `URLSearchParams` or `FormData` instance, Action View
`FormBuilder` instances should support encoding a method name the same
way it does for other fields.

For instance, consider this HTML:

```html
<button>Publish</button>
<button name="post[draft]" value="true">Save as draft</button>
```

Clicking the "Publish" button would submit the form without encoding any
additional `[name]` and `[value]` pairs.

Clicking the "Save as draft" button would submit the form and encode
`post[draft]=true` into the submission.

This commit changes the `FormBuilder#button` method to interpret a
`Symbol` as the first argument as a method name argument, and encodes
its value based on the form's `model:` or `scope:` value:

```erb
<%= form.button :draft, value: true do %>
  Save as draft
<% end %>
end
<%# =>  <button name="post[draft]" value="true" type="submit">  %>
<%#       Save as draft                                         %>
<%#     </button>                                               %>
```

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2021-11-15 21:40:06 +00:00
Rafael Mendonça França 876d2ff904
Merge PR #43409 2021-11-15 21:20:34 +00:00