我有如下因素導軌 - 遍尋不查詢
Sale.rb
belongs_to :client
belongs_to :user
has_many :line_items, dependent: :destroy
has_many :products, through: :line_items
has_many :deposits
accepts_nested_attributes_for :line_items, reject_if: :all_blank, allow_destroy: true
sales_controller.rb
def index
@q = Sale.ransack(params[:q])
@sales = @q.result(distinct: true)
end
的意見/管理/銷售/ index.html.erb
<%= search_form_for @q, url: admin_sales_path, html: {class: "form-inline"} do |f| %>
<%= f.search_field :sku, placeholder: "SKU", class: "input perfil" %>
<%= f.submit 'search', class: "btn btn-primary" %>
<% end %>
<table class="table">
<thead>
<tr>
<th><%= sort_link @q, :sku, "SKU" %></th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @sales.each do |sale| %>
...
<% end %>
</tbody>
</table>
最後這是l og從終端:
Started GET "/admin/sales?utf8=%E2%9C%93&q%5Bsku%5D=sample&commit=search" for ::1 at 2016-11-24 00:29:33 -0600
Processing by Admin::SalesController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"sku"=>"sample"}, "commit"=>"search"}
Sale Load (0.3ms) SELECT DISTINCT "sales".* FROM "sales"
Rendered admin/sales/index.html.erb within layouts/admin (7.5ms)
Completed 200 OK in 361ms (Views: 346.0ms | ActiveRecord: 1.6ms)
一切似乎工作正常,但似乎沒有被過濾。
作爲說明我應用這種相同的方法爲其他模型,他們工作正常。
<%= f.search_field:sku_eq,佔位符:「SKU」,類:「輸入perfil」%> 試試吧 –
哇我很慚愧,超級初學者錯誤,你是對的問題在於: sku_eq(「_eq」結尾)。謝謝。 – user3754535
將其添加到解決方案請accpet –