Dynamically adding paper_trail to translations in Rails5

236 Views Asked by At

I have an application that translates some model data and I would like to version this data. So this is my setup:

  • Rails 5.1.4
  • Ruby 2.4.1 (with RVM)
  • Globalize @ master
  • PaperTrail for versioning of the translations

I have created a pull-request that should add rails 5 functionality to the globalize-versioning gem.

I already did this:

  • Update the gemspec and the Gemfile to use the latest gems.
  • Fix deprecated ruby calls
  • Update the .travis.yml so that tests are run.

Now all tests in the projects fail and I can't quite figure out how to add the paper_trail functionality to the translations objects from globalize.

1

There are 1 best solutions below

0
On

You changed the alias_method_chain wrongly.

alias_method :versioning, :setup_translates!
alias_method :setup_translates!, :versioning

This only aliases versioning and setup_translates!. What alias_method_chain actually tries is to make sure a overriden method is still callable.

So this:

alias_method_chain :setup_translates!, :versioning

should be changed to:

alias_method :setup_translates_without_versioning!, :setup_translates!
alias_method :setup_translates!, :setup_translates_with_versioning!

Try if this solves the issues.

source: alias_method_chain