Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating Basic Search Form in Rails

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 296
    Comment on it

    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="&#x2713;" />
      <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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: