Мне нужно искать по :total_in_stock
в рансаке. Но это дает ошибку для undefine total_in_stock.
Я пытался решить эту проблему, я узнал, что только атрибуты 'ransackable_attributes (: admin)' могут быть найдены.
@search = @collection.ransack(params[:q])
@collection = @search.result(distinct: true).page(params[:page]).per(params[:per_page] || Spree::Config[:admin_products_per_page])
Вот подробности консоли рельсов.
2.5.3 :003 > Spree::ShopVariantPrice
=> Spree::ShopVariantPrice(id: integer, shop_id: integer, variant_id: integer, variant_price_submission_id: integer, currency: string, price: decimal, created_at: datetime, updated_at: datetime, shop_and_price: integer, deleted_at: datetime, track_inventory: boolean, cost_price: decimal, orders_count: integer, stores_count: integer, store_id: integer, total_in_stock: integer, display_on: string, list_price: decimal, available_on: datetime, discontinue_on: datetime)
2.5.3 :004 > Spree::ShopVariantPrice.ransackable_attributes(:admin)
=> ["id", "name", "updated_at", "created_at"]
Вот форма поиска, написанная на слим.
div data-hook="admin_products_sidebar"
= search_form_for @search, url: stocks_shop_admin_shop_store_variants_path do |f|
- locals = {f: f}
.row data-hook="admin_products_index_search"
.col-xs-12.col-md-6
.form-group
= f.label :product_name_cont, Spree.t(:name)
= f.text_field :product_name_cont, size: 15, class: "form-control js-quick-search-target"
.col-xs-12.col-md-6
.form-group
= f.label :variant_total_in_stock_eq, Spree.t(:ariant_total_in_stock_eq)
= f.number_field :total_in_stock_eq, size: 15, class: 'form-control'
.col-xs-12.col-md-6
.form-actions data-hook="admin_products_index_search_buttons"
= button Spree.t(:search), 'search'
Мне нужен поиск, но выдает следующую ошибку.
Completed 500 Internal Server Error in 2001ms (ActiveRecord: 61.6ms)
undefined method `variant_total_in_stock_eq' for #<Ransack::Search:0x00007fbc37d44c48> excluded from capture: No host specified, no public_key specified, no project_id specified
ActionView::Template::Error (undefined method `variant_total_in_stock_eq' for #<Ransack::Search:0x00007fbc37d44c48>):
9: .col-xs-12.col-md-6
10: .form-group
11: = f.label :variant_total_in_stock_eq, Spree.t(:ariant_total_in_stock_eq)
12: = f.number_field :varient_total_in_stock_eq, size: 15, class: 'form-control'
13: .col-xs-12.col-md-6
14: .form-group
15: = f.label :variant_total_in_stock_cont, Spree.t(:total_in_stock)
app/views/spree/shop_admin/shop_variant_prices/_stock_filter.html.slim:12:in `block in _ac7c67bd224087c40f54163747fc855d'