Hi Friends,
As we know that, currently there are plenty of content based sites and we usually see a search box within that, to search any topic that is available in that site. So today we will be discussing on how to create a basic search form in rails.
For creating a search form, basically you need a input box and submit button. The request for search should be get as it allows user to bookmark a specific search for future visit. The search form in rails will look something like this:
<%= form_tag("/search-in-site", method: "get") do %>
<%= label_tag(:q, "Search:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>
It will produce the following HTML result:
<form accept-charset="UTF-8" action="/search-in-site" method="get">
<input name="utf8" type="hidden" value="✓" />
<label for="q">Search:</label>
<input id="q" name="q" type="text" />
<input name="commit" type="submit" value="Search" />
</form>
To know more about Rails Form Helpers. Click on the link given below.
Form Helpers in Rails
0 Comment(s)