Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ancestry overrides acts_as_tree method even when acts_as_tree is installed #39

Closed
benevolentmadman opened this Issue · 5 comments

5 participants

Alex Spencer Jim Sagevid Stefan Kroes hotsen Jean Mertz
Alex Spencer

I have model (X) using acts_as_tree, I want that model to continue using acts_as_tree. After adding ancestry to my Gemfile (for use in a different model (Y)), ancestry is now being called instead of acts_as_tree in X and failing my tests thusly:

NoMethodError:
undefined method `ancestry' for X

It appears that the following code is not working as expected:

if !respond_to?(:acts_as_tree)
    alias_method :acts_as_tree, :has_ancestry
end
Jim Sagevid

I also have this issue. The thing is that because you never know the load order of a plugin that adds the acts_as_tree method. Because of this, using respond_to?(:acts_as_tree) will probably fail to detect such plugins/gems.

I forked the rep and added a check for the ActsAsTree module instead. This fixes the problem only if you're using a plugin that defines the module ActsAsTree. You can use my version by specifying [gem 'ancestry', :git => 'git://github.com/jims/ancestry.git'] in your gemfile.

I'll add a pull request if the author wants to incorporate these changes :>

Stefan Kroes
Owner

Fix by Jims was released in Ancestry 1.2.4. Thank you!

hotsen

I still have problems with this issue. We are using the official acts_as_tree plugin from https://github.com/rails/acts_as_tree

This version doesn't define an ActsAsTree module, so the patch doesn't work. Maybe it would be better to let the developer interface these aliases via an initializer or macro configuration option? As an example I'd like to choose not to alias the acts_as_tree method at all, because I don't care about ancestry downwards compatibility.



has_ancestry :alias_acts_as_tree => false

Jean Mertz

hotsen, see the notice on that repository:

NOTICE: official repository moved to https://github.com/amerine/acts_as_tree

See if that fixes the problem.

hotsen

No sorry, it's the problem same there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.