Ruby on Rails - creating a search form in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
To create a search form, enter the given below code
<%= form_tag("/search", method: "get") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- form_tag: This is the default helper for creating a form. It's first parameter, /search is the action and the second parameter specifies the HTTP method. For search forms, it is important to always use the method get
- label_tag: This helper creates an html <label> tag.
- text_field_tag: This will create an input element with type text
- submit_tag: This creates an input element with type submit