complètement bloqué sur Ransack le tri avec les associations. Vous voulez trier la liste des produits de différentes marques.Ransack - Tri association action show
Marques Modèle:
class Brand < ApplicationRecord
has_many :products
end
Controller Marque:
def show
@brand = Brand.find(params[:id])
@q = @brand.products.ransack(params[:q])
end
Marque Vue:
<%= search_form_for @q, url: products_path(params[:id]) do |f| %>
<%= f.search_field :brand_products_title_cont %>
<%= sort_link(@q, :brand_products_id)%>
<%= sort_link @q, :brand_products_title %>
<% end %>
Je peux filtrer o n le produit.title sans problèmes, mais le tri ne fonctionne pas. Quelle est mon erreur en pensant?
est ici la sortie de SQL après avoir cliqué sur le tri par titre:
Brand Load (0.3ms) SELECT `brands`.* FROM `brands` WHERE `brands`.`id` = 2 LIMIT 1
CACHE (0.0ms) SELECT `brands`.* FROM `brands` WHERE `brands`.`id` = 2 LIMIT 1 [["id", 2], ["LIMIT", 1]]
Rendering brands/show.html.erb within layouts/application
Product Load (19.5ms) SELECT `products`.* FROM `products` WHERE `products`.`brand_id` = ‚BRANDNAME'
Question de débogage: à quoi ressemble votre chaîne de requête après avoir cliqué sur le lien de tri? – coreyward
double possible: http://stackoverflow.com/questions/12065592/rails-sorting-associations-with-ransack – coreyward