Skip to content

Commit

Permalink
Support alt paper_trail versions assoc name
Browse files Browse the repository at this point in the history
When using PaperTrail as an auditing gem, you can specify an alternative versions association by defining the `versions` hash in the `has_paper_trail` call. Initialization of PaperTrail (per model) stores the name of the association (since paper-trail-gem/paper_trail@3032b53, 23rd of July 2011) in `versions_association_name`. Using this method we can retrieve the history of a model when it uses a different name for the versions association.

For example, using the following configuration won't break the auditing_adapter with this change:
```ruby
has_paper_trail(
  version: :paper_trail_version,
  versions: {
    name: :paper_trail_versions,
  },
)
```
  • Loading branch information
fuegas committed Apr 22, 2021
1 parent 7962a19 commit cec972c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Expand Up @@ -116,7 +116,7 @@ def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, p

current_page = page.presence || '1'

versions = object.nil? ? versions_for_model(model) : object.versions
versions = object.nil? ? versions_for_model(model) : object.send(model.model.versions_association_name)
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, current_page).per(per_page)
Expand Down

0 comments on commit cec972c

Please sign in to comment.