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

Issue with STI and namespaced Rails models #207

Closed
wtn opened this issue Mar 30, 2016 · 2 comments
Closed

Issue with STI and namespaced Rails models #207

wtn opened this issue Mar 30, 2016 · 2 comments

Comments

@wtn
Copy link

wtn commented Mar 30, 2016

I tried creating a model called Catalog::Entry using closure_tree 6.0.0 and rails 4.2.6. Running rails generate closure_tree:migration Catalog::Entry or loading the app causes an exception. Here's the backtrace.

$ rails g closure_tree:migration Catalog::Entry
/project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/closure_tree/active_record_support.rb:18:in `remove_prefix_and_suffix': undefined method `start_with?' for nil:NilClass (NoMethodError)
    from /project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/closure_tree/support.rb:59:in `hierarchy_table_name'
    from /project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/closure_tree/support.rb:50:in `hierarchy_class_for_model'
    from /project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/closure_tree/has_closure_tree.rb:21:in `has_closure_tree'
    from /project/rails_app/app/models/catalog/entry.rb:3:in `<class:Entry>'
    from /project/rails_app/app/models/catalog/entry.rb:1:in `<top (required)>'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `load'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:457:in `block in load_file'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:647:in `new_constants_in'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:456:in `load_file'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:354:in `require_or_load'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:184:in `const_missing'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:263:in `const_get'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:263:in `block in constantize'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `each'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `inject'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:259:in `constantize'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
    from /project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/generators/closure_tree/migration_generator.rb:33:in `target_class'
    from /project/lib/ruby/gems/2.2.0/gems/closure_tree-6.0.0/lib/generators/closure_tree/migration_generator.rb:37:in `ct'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
    from /project/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/generators.rb:157:in `invoke'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/generate.rb:13:in `<top (required)>'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /project/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:130:in `generate_or_destroy'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:50:in `generate'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /project/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
@wtn
Copy link
Author

wtn commented Mar 30, 2016

I was able to work around the issue by declaring the class abstract after invoking has_closure_tree.

has_closure_tree
self.abstract_class = true # no exception

Maybe something for the documentation?

@seuros
Copy link
Member

seuros commented Jul 17, 2016

Thanks for sharing the solution!

@seuros seuros closed this as completed Jul 17, 2016
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

No branches or pull requests

2 participants