rails button_tag Code Example

Last Updated On Monday 30th May 2022

Use button_to

button_to Generates a form containing a single button that submits to the URL created by the set of options.

  • Rails thinks that button_to is a safer tool for representing delete requests.
  • Interesting! The button_to helper works very similarly to link_to
	<%= button_to "Delete Image", image_path(@image), method: :delete %>

Code Example

	<% if type == "img" %>
  <%= button_to "View Image", img_path(curImage), method: :get %>
  <%= button_to "Edit Image", edit_path(curImage), method: :get %>
<% end %>