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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config.action_view.button_to_generates_button_tag work #41055

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions actionview/lib/action_view/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class Railtie < Rails::Engine # :nodoc:
end
end

config.after_initialize do |app|
button_to_generates_button_tag = app.config.action_view.delete(:button_to_generates_button_tag)
unless button_to_generates_button_tag.nil?
ActionView::Helpers::UrlHelper.button_to_generates_button_tag = button_to_generates_button_tag
end
end

config.after_initialize do |app|
ActionView::Helpers::AssetTagHelper.image_loading = app.config.action_view.delete(:image_loading)
ActionView::Helpers::AssetTagHelper.image_decoding = app.config.action_view.delete(:image_decoding)
Expand Down Expand Up @@ -81,13 +88,6 @@ class Railtie < Rails::Engine # :nodoc:
PartialRenderer.collection_cache = app.config.action_controller.cache_store
end

initializer "action_view.button_to_generates_button_tag" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::UrlHelper.button_to_generates_button_tag =
app.config.action_view.delete(:button_to_generates_button_tag)
end
end

config.after_initialize do |app|
enable_caching = if app.config.action_view.cache_template_loading.nil?
app.config.cache_classes
Expand Down
4 changes: 4 additions & 0 deletions guides/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ Defaults to `'signed cookie'`.

* `config.action_view.preload_links_header` determines whether `javascript_include_tag` and `stylesheet_link_tag` will generate a `Link` header that preload assets. This defaults to `true`.

* `config.action_view.button_to_generates_button_tag` determines whether `button_to` will render `<button>` element, regardless of whether or not the content is passed as the first argument or as a block.

### Configuring Action Mailbox

`config.action_mailbox` provides the following configuration options:
Expand Down Expand Up @@ -1040,6 +1042,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
`config.load_defaults` sets new defaults up to and including the version passed. Such that passing, say, `6.0` also gets the new defaults from every version before it.

#### For '6.2', defaults from previous versions below and:
- `config.action_view.button_to_generates_button_tag`: `true`
- `config.active_support.key_generator_hash_digest_class`: `OpenSSL::Digest::SHA256`

#### For '6.1', defaults from previous versions below and:
Expand Down Expand Up @@ -1100,6 +1103,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
- `config.action_dispatch.cookies_same_site_protection`: `nil`
- `config.action_mailer.delivery_job`: `ActionMailer::DeliveryJob`
- `config.action_view.form_with_generates_ids`: `false`
- `config.action_view.button_to_generates_button_tag`: `false`
- `config.active_job.retry_jitter`: `0.0`
- `config.active_job.skip_after_callbacks_if_terminated`: `false`
- `config.action_mailbox.queues.incineration`: `:action_mailbox_incineration`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.

# button_to view helpers consistently render <button> elements.
# Rails.application.config.action_view.button_to_generates_button_tag = false
# `button_to` view helper will render `<button>` element, regardless of whether
# or not the content is passed as the first argument or as a block.
# Rails.application.config.action_view.button_to_generates_button_tag = true

# Change the digest class for they key generators to `OpenSSL::Digest::SHA256`.
# Changing this defaults means invalidate all encripted messages generated by
Expand Down
25 changes: 25 additions & 0 deletions railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,31 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_equal true, ActionView::Helpers::FormTagHelper.default_enforce_utf8
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag is true by default" do
app "development"
assert_equal true, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag is false by default for upgraded apps" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'
app "development"

assert_equal false, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag can be configured via config.action_view.button_to_generates_button_tag" do
remove_from_config '.*config\.load_defaults.*\n'

app_file "config/initializers/new_framework_defaults_6_2.rb", <<-RUBY
Rails.application.config.action_view.button_to_generates_button_tag = true
RUBY

app "development"

assert_equal true, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::AssetTagHelper.image_loading is nil by default" do
app "development"
assert_nil ActionView::Helpers::AssetTagHelper.image_loading
Expand Down