Rails provides many methods that render out HTML tags, allowing for easy customization. However, some of the Rails methods do not offer consistent results. One such example, until recently, was the button_to helper method.
This is how it works,
the helper method render
<input type="submit"> when passed String contents
<button type="submit"> when passed a block.
Though this difference is subtle,
it will lead to surprises later.
One such quirky behavior is when
button_to renders out an
it sets the button content as the
This behavior is not obvious and prevents us from setting custom input values.
In cases where the
input value is set to nil,
it provides an opportunity for applications to encode their custom values
to be sent back to the server for processing.
This could cause additional security concerns.
With the updated Rails 7,
button_to always renders out a consistent output.
Here’s how it works now.
Since this change could affect many applications running in the real world, the Rails team has decided to make this a configurable option.
To support the original behavior of button_to rendering
<input type="submit"> elements when invoked without a block,
app.config.button_to_generates_button_tag configuration flag.
it’s set to true and ensures that all button_to calls render
To revert to the original behavior,
set it to false.