Rails button_to vs. HTML Button Tag

button_to like all others helpers for the views in Rails (e.g. link_to, form_for, image_tag…) simply converts your Rails command in HTML code. We could say that is a shortcut to write “pure HTML”.

In your case, for button_to, you can see the reference (and what is printed) here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to

For example:

<%= button_to "New", action: "new" %>
# => "<form method="post" action="/controller/new" class="button_to">
#      <div><input value="New" type="submit" /></div>
#    </form>"

I suggest you to use these helpers, because is more “Rails” and this improve your speed of coding.

Leave a Comment