Permalink
Browse files

Support for paper_trail custom version classes

  • Loading branch information...
1 parent 4d5fa97 commit 959e1bd4e47e0369d264b58bbbe972ff863767cd @vyorkin vyorkin committed Feb 3, 2014
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
@@ -87,13 +87,24 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p
sort = :created_at
sort_reverse = 'true'
end
- versions = @version_class.where item_type: model.model.name
+
+ model_name = model.model.name
+
+ versions = version_class_for(model_name).where item_type: model_name
versions = versions.where item_id: object.id if object
versions = versions.where('event LIKE ?', "%#{query}%") if query.present?
versions = versions.order(sort_reverse == 'true' ? "#{sort} DESC" : sort)
versions = all ? versions : versions.send(Kaminari.config.page_method_name, page.presence || '1').per(per_page)
versions.collect { |version| VersionProxy.new(version, @user_class) }
end
+
+ def version_class_for(model_name)
+ klass = model_name.constantize
+ .try(:version_class_name)
+ .try(:constantize)
+
+ klass || @version_class
+ end
end
end
end

0 comments on commit 959e1bd

Please sign in to comment.