Home>

I routed using collection and set up my own search action, but I am in trouble because the search results are not displayed. The path to the search action is specified in the form. The value of the parameter seems to be sent correctly, but html is not returned.

Form to skip to search action
    <% = form_with (url: search_folders_path, method:: get, class: "form-form-inline my-2 my-lg-0") do | f |%>
      <% = f.text_field: keyword, placeholder: "Search", class: "form-control mr-sm-2"%>
      <% = f.submit "Search", class: "btn btn-outline-success my-2 my-sm-0"%>
    <% end%>
    
</nav>
Search action part
  def search
    @folders = Folder.all
    @documents = Document.search (params [: keyword])
    if @documents
      return search_folders_path
    else else
      redirect_to root_path
    end
  end
View of search actions in controller

<% = render "documents/side_bar"%>
  
    
    <% = render "documents/folders"%>
    
    
      
      <% @ documents.each do | document |%>
          
         <% = document.document_name%>
         <% = document.created_at%>
          
          
          
        <% document.images.each do | image |%>
          <% = image_tag image.preview (resize: "1000x1050")%>
        <% end%>
      <% end%>
      
    
  
def self.search (search)
    if search! = ""
      Document.where ("document_name LIKE (?)", "% # {Search}%")
    end
  end
  • Answer # 1

    It was solved by using form_tag instead of form_with.