Ads by ProfitSence
Close

Create a form with a custom action and method in Ruby

Last Updated on Wednesday 5th Oct 2022

Example

			
					<%= form_tag("/search", method: "get") do %>
  <%= label_tag(:q, "Search for:") %>
  <%= text_field_tag(:q) %>
  <%= submit_tag("Search") %>
<% end %>

			
	

The HTML Output

			
					<form accept-charset="UTF-8" action="/search" method="get">
  <input name="utf8" type="hidden" value="✓" />
  <label for="q">Search for:</label>
  <input id="q" name="q" type="text" />
  <input name="commit" type="submit" value="Search" />
</form>