Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails中显示搜索结果?_Ruby On Rails - Fatal编程技术网

Ruby on rails 如何在rails中显示搜索结果?

Ruby on rails 如何在rails中显示搜索结果?,ruby-on-rails,Ruby On Rails,当我搜索store_item时,我有两个模型indent和store_item如何在indent index页面上显示搜索结果。这是我的代码: 缩进/新缩进: _store_item.html.erb 单价: 批号: 提供: 缩进控制器: class IndentsController

当我搜索store_item时,我有两个模型indent和store_item如何在indent index页面上显示搜索结果。这是我的代码:

缩进/新缩进: _store_item.html.erb

单价:

批号:
提供:
缩进控制器:
class IndentsController
缩进索引:

缩进号
商场
预期日期
描述
要求的
悬而未决的
发行量
发行类型
销毁缩进
单价
批号
可用

您的index\u indent.html.erb文件在哪里?除非另有规定,否则控制器中的index_indent方法将查找并提供index_indent.html.erb文件。因此,您需要直接在该文件中呈现@storeitems,或者从index_indent.html.erb中呈现部分_store_item.html.erb,如下所示:添加了indent_索引页。我按照您的指示尝试在indent_索引页中呈现部分文件,但它仍然显示所有搜索的项目。“我想要的是当我从下拉列表中搜索store_项目时,如何在缩进索引页中显示搜索到的store_项目。@PriyankaBabar您解决了问题吗?否@Vishal我仍在处理它。在缩进表单中,当我搜索store_项目时,它会以单个值显示,即单价、批次号、,数量是正确的,但如何在缩进索引页上显示相同的内容。问题是现在它显示缩进索引上的所有存储项page@PriyankaBabar我不明白你为什么要做这么多只显示商店物品的代码。当用户选择任何搜索项目时,将显示搜索项目详细信息。正确的?
<div class="form-group">
 <%=render 'item'%>
</div>

<div class="col-md-3"></div>
<div class="col-md-7">
<h3>Store Item</h3>
<div class="form-group">
 <%= form_for :indent, url:{action:'search_item'}, method: :get,remote:true,html:{id: "user_form"} do |f|%>
 <tbody>
   <tr>
    <td class="col-3"><%= f.select :id, StoreItem.all.collect {|b| [b.item_name,b.id]},{prompt:"Select Item"},{onchange:"$('#user_form').submit();"}%></td>
   </tr>
 <%end%>
</tbody>
</div>
</div>
<div class="search_item"></div>
$('.search_item').html("<%= j render 'store_item' %>");
  def self.search_item(a)
   StoreItem.where("id LIKE ?", "%#{a}%")
  end
<div class="col-md-3"></div>
<div class="col-md-7">
      <% @storeitems.each do |s| %>
        <tr>
          <th>Unit Price</th>:
          <td><%= s.unit_price %></td>
          <br>
          <th>Batch No</th>:
          <td><%= s.batch_no%>
          <br>
          <th>Available</th>:
          <td><%= s.quantity%>
        </tr>
      <% end %>   
</div>
</div>  
class IndentsController < ApplicationController
    def index_indent
     @stores = Store.all
     @indents = Indent.all
     @search = params[:indent_id]
     @storeitems = StoreItem.search_item(@search)
    end

def search_item
 @storeitems = StoreItem.search_item(params[:indent][:id])
end

def create_indent
 @indent = Indent.new(indent_params)
 if @indent.save
    redirect_to index_indent_indents_path
 else
  render 'index_indent'
 end
end
<table id="datatable" class="table table-striped table-bordered responsive">
   <thead>
    <tr>
      <th>Indent No</th>
      <th>Store</th>
      <th>Expected Date</th>
      <th>Description</th>
      <th>Required</th>
      <th>Pending</th>
      <th>Issued Quantity</th>
      <th>Issued Type</th>
      <th>Destroy Indent</th>
      <th>Unit Price</th>
      <th>Batch No</th>
      <th>Available</th>
      <th colspan="3"></th>
    </tr>
  </thead>

   <% @indents.each do |i| %>
    <tr>  
        <td><%= i.indent_no %></td>
        <td><%= @stores.name %></td>
        <td><%= i.expected_date%></td>
        <td><%= i.description %></td>
        <td><%= i.required %></td>
        <td><%= i.pending %></td>
        <td><%= i.issued_qty %></td>
        <td><%= i.issued_type %></td>
        <td><%= link_to 'Destroy', destroy_indent_indent_path(i), method: :delete, data: { confirm: 'Are you sure?' },class: "btn btn-danger btn-sm" %></td>

        <%= render partial: 'store_item' %>
      </tr>
 <%end%>