Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack exception when calling translates multiple times #50

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

odarriba
Copy link

In a project I'm working on, I have this models:

class Object < ActiveRecord::Base
  translates :name
end
class Table < Object
  translates :wadus
end

As you can see, I'm using Single Table Inheritance to store different kind of Objects in the same table. As I want to translate both fields, I have to call translates method two times (I could call it only once in Object class, but :wadus field it's supposed to be only un Table model).

This causes an alias_method loop that ends in an Stack level too deep exception. To fix it, I've create a patch that verifies if the model already has translated attributes, in which case avoids creating the aliases, so this loop never happens.

And thanks for your work in this gem, it's awesome!

@odarriba
Copy link
Author

ping @lminaudier ?

I think that this is a huge improvement, because using translates multiple times causes a critical exception 👎

Also, Test has been fixed to avoid crashing in 1.9.3.

@odarriba
Copy link
Author

ping @robworley ? :)

@lminaudier
Copy link
Contributor

Hi @odarriba,

First; thanks for the report and the PR.

Then, by any chance could you add some specs ?

@odarriba
Copy link
Author

@lminaudier there you go!

I've added specs to test that a model that have called translates method twice, doesn't crash and can save and restore translated data.

Hope this helps :)

Thanks for the reply!

@odarriba
Copy link
Author

Any news on this?

@odarriba
Copy link
Author

odarriba commented Jun 7, 2016

@lminaudier any news? Is there any chance to maintain and improve this gem?

@cfabianski
Copy link
Contributor

I couldn't reproduce (and apparently the test provided doesn't fail either without your fix). Could you please try again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants