Jonathan Bennett

Rewriting form action and method

Did you know that buttons in forms can override the method and action of its form?

<%= form_with url: search_path do |form| %>
	<%= form.text_field :q %>
	
	<%= form.submit "Internal Search" %>
	<%= form.submit "Google Search", formmethod: :get, formaction: "https://google.com" %>
<% end %>

This is a little contrived of an example, but using this approach allows for some very elegant use of Hotwire… next time.