Last active
March 18, 2020 04:37
-
-
Save landovsky/eda9e86ffee908d815cae8cb68fb1b4c to your computer and use it in GitHub Desktop.
Custom ransacker for Active Admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom search ransacker | |
# models/concerns/ransackers | |
module Ransackers | |
module Candidate | |
extend ActiveSupport::Concern | |
included do | |
ransacker :candidate_approved_at, | |
formatter: proc { |date| | |
last_review = ReviewStatusChange.select('DISTINCT ON (candidate_id) candidate_id, review_status_id, created_at') | |
.order(:candidate_id, created_at: :desc).to_sql | |
joins("JOIN (#{last_review}) AS last_review ON last_review.candidate_id = \"Candidates\".id") | |
.where("last_review.created_at >= '#{date}'").where(last_review: { review_status_id: 2 }) | |
.map(&:id) | |
} do |parent| | |
parent.table[:id] | |
end | |
end | |
end | |
# ransacker implementation in active admin view | |
filter :candidate_approved_at_in_all, label: 'Candidate approved', as: :select, | |
collection: proc { days_ago_select_values([1, 3, 7, 14, 30]) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment