Skip to content

How to add a single button using button to

macourtney edited this page Sep 13, 2010 · 3 revisions

If all you need is a button from a form, but not have anything else in a form, you can use button-to.

To create a button which points back to the same controller and action but with text “Submit” use:

(button-to "Submit" request-map)

If you want to point to a different action you can pass a params map:

(button-to "Submit" request-map { :action "show" })

The params map has the same options as form-for. However, :html-options is applied only to the button and not the form tag.

Button-to also accepts a function for text:

(button-to #(:action %) request-map { :action "show" })

The above button-to call displays “show” as it’s text.

Clone this wiki locally