我是 rails 的新手,我不确定我的代码发生了什么,但我想通过使用 id 搜索来过滤数据库中的数据我该怎么做

I am new on rails i not sure what is going on my code but I want to filter data from database by searching using id how can i do it

我正在尝试生成一个代码来跟踪组织内循环的文档。我已经完成了添加员工、添加文档类型和登录的其他代码,现在我正在努力创建文档表单并从我创建的文档中进行搜索。此代码用于搜索:

controller#show  
    def show
        @generate_documents = GenerateDocument.where('Reciever LIKE?',"%#{params[:search]}%")
        # @generate_documents = GenerateDocument.all
      end

views/show
    <%= form_tag generate_document_path, :method => :get do %>
    <p>
      <%= text_field_tag :search, params[:search] %>
      <%= submit_tag "Search" %>
    </p>
    <% end %>
    <!-- end of seaerch form -->


    <!-- loading data from database and displaying then in a list format BEGIN -->
    <ul> 
      <% @generate_documents.each do |generate_document| %>
      <li>


         <%= link_to generate_document.Reciever, edit_generate_document_path(generate_document) %>
          </li>
      <% end %>`enter code here`
    </ul>
    <!-- 
    END LISTING -->

    <%= link_to 'New Generate Document', new_generate_document_path %>

即使我是 rails 的新手,但我可以帮助您了解将参数从视图传递到控制器的基础知识,因此您可以使用:

    :url => {:controller => "name_of_your_controller", :action => "action_to_be_perforemed", :id => "whatever id you want"}

否则您也可以在 url 中传递对象,就像我们在编辑请求时所做的那样

  <%= link_to "Edit", edit_post_path(@edit)%>

这将给出特定 post 的 :id。 希望这可以帮助你。