ransack

Rails, Ransack: How to search HABTM relationship for “all” matches instead of “any”

给你一囗甜甜゛ 提交于 2019-11-27 18:28:30
问题 I'm wondering if anyone has experience using Ransack with HABTM relationships. My app has photos which have a habtm relationship with terms (terms are like tags). Here's a simplified explanation of what I'm experiencing: I have two photos: Photo 1 and Photo 2. They have the following terms: Photo 1: A, B, C Photo 2: A, B, D I built a ransack form, and I make checkboxes in the search form for all the terms, like so: - terms.each do |t| = check_box_tag 'q[terms_id_in][]', t.id If I use: q[terms

Ransack sort on count of HABTM or HMT associated records

会有一股神秘感。 提交于 2019-11-26 23:33:50
问题 I have a HABTM relationship between the Theme and Quote models. The themes index view displays the count of quotes associated with each theme. I'd like to add a Ransack sort_link on that column, so the themes can be sorted by their count of associated quotes . I have done this successfully with has_many associations using a counter cache column, but Rails does not support counter cache columns for HABTM associations. So far, I've got a scope that adds a virtual attribute called quotes_count