Today I Learned

hashrocket A Hashrocket project

How to add hidden fields to button_to

The button_to helper take a params key to add hidden fields to the form it renders:

<%= button_to "Delete", users_path, method: :delete, params: {send_email: false} %>


<form class="button_to" method="post" action="/users">
<input type="hidden" name="_method" value="delete" autocomplete="off">
<button type="submit">Delete</button>
<input type="hidden" name="authenticity_token" value="8nOHRzvQIev3XHW6YrEJUIohVGLm0PKOPNly8ovPdDtF75eyBj5Rvz_1FzDmVybbJ3YyfC7YExtfRQC3_H5NNw" autocomplete="off">
<input type="hidden" name="send_email" value="false" autocomplete="off">
See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.