Skip to content

Instantly share code, notes, and snippets.

@yorzi
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorzi/34ddf5d02cbf01137a92 to your computer and use it in GitHub Desktop.
Save yorzi/34ddf5d02cbf01137a92 to your computer and use it in GitHub Desktop.
paper_trail_history.rb
class PaperTrailHistory < PaperTrail::Version
def self.compose_query(params)
condition = ""
condition <<
(params[:type].present? ? "whodunnit NOT IN (?)" : "whodunnit IN (?)")
condition << " AND object_changes ILIKE '%#{params[:q]}%'" if params[:q].present?
condition
end
def self.find_history(params)
condition = PaperTrailHistory.compose_query(params)
PaperTrailHistory.where(condition, User.admin_ids).order('created_at DESC').page(params[:page])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment