Search code examples
ruby-on-railsbutton-to

Rails button_to for Custom Name / Value Submit


In Rails is it possible to achieve an HTML output like this using button_to?

<button type="submit" value="1" name="id">Type 1</button>
<button type="submit" value="2" name="id">Type 2</button>

What are the reasons for using button_to over manually entering the HTML in my form?

...

EDIT:

Perhaps I should rephrase this? Seems the better way would be to add some hidden fields to the button_to form. It doesn't seem like I can do this.

So what is the correct Rails solution to pass extra hidden fields to a dynamic form generated via a button_to? Or should I just build a form manually?

e.g. I have:

button_to "Download", items_path(:release_id => release), :remote => true

and I want to pass an extra parameter in the form POST format => "download"


Solution

  • Seems my answer was to use the form_tag helper