Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can button_to generate <button> tag instead of <input type="submit" />?

Rather than

<input type="submit" />

I want to output

<button>

using the button_to method (rails 3.0.0)

Is this possible?

like image 511
Graham Avatar asked Sep 18 '10 10:09

Graham


People also ask

Is input type submit same as button?

input suggests that the control is editable, or can be edited by the user; button is far more explicit in terms of the purpose it serves. Easier to style in CSS; as mentioned above, FIrefox and IE have quirks in which input[type="submit"] do not display correctly in some cases.

Can button type be submit?

submit : The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form> , or if the attribute is an empty or invalid value. reset : The button resets all the controls to their initial values, like <input type="reset">.

What can I use instead of a button in HTML?

You use css and style a link <a> to look like a button.


1 Answers

As of the latest version of Rails (4.0.2, not sure about previous versions) passing a block to button_to invokes branch logic in the helper that creates a button element instead of an input.

For example, if you wanted to make a 'delete' button element in haml, bootstrap & fontawesome (my use case):

= button_to(foo_path(@foo),
  class: 'btn btn-sm', method: :delete, remote: true) do
  <i class="fa fa-times"></i>

If you want them to just always be button elements no matter what, you could always have your button content inside a block instead of the first argument. Not sure what the trade-off is there.

like image 155
Woahdae Avatar answered Oct 11 '22 10:10

Woahdae