Created a search function with rails5.
It is created with form_tag, and when searching, the result is displayed on a separate page.

Therefore, get the characters entered by the user on the search result page,
Example: "Search results for (entered characters)"

If i do<% =: search%>, it will be displayed as it is like "search search results".

Search form

<% = form_tag (search_posts_path,: method =>"get") do%>
          <% = text_field_tag: search, '', class: "application-text", placeholder: "Looking for something?"%>
            <% = button_tag type: "submit",: name =>nil, class: "search-btn" do%>
            <% end%>
        <% end%>

Search function part controller

def search
    @posts = Post.all.search (params [: search])
  • Answer # 1

    <% = params [: search]%>

Related articles