vigetlabs/active_admin_associations — pull request #11 by laspluviosillas (2013-03-06 01:18:38+00:00)
Title: Allow autocompletion to work for namespaced models.

At the moment, when trying to setup the "autocomplete" functionality with a model that is under a package, the routing breaks.

Take the following model as an example:
"OleCore::Distributor"

This model, on [this line](https://github.com/vigetlabs/active_admin_associations/blob/master/lib/formtastic/inputs/token_input.rb), is converted to the following path:

*ole_core_distributor*

Which is then received by the autocomplete processor on [https://github.com/vigetlabs/active_admin_associations/blob/master/app/controllers/autocomplete_controller.rb#L17](this line), which converts the path to:

*OleCoreDistributor*

Which, obviously, causes a ModelNotFound error to be thrown from rails.

The problem here is that when using a package name, the package cannot be converted to underscores, it has to be converted to slashes. By replacing the line on the first link (see my commit), the reflection generated is the following:

*ole_core/distributor*

Which works as long as you use the following configuration option in application.rb

config.aa_associations.autocomplete_models = %w(ole_core/distributor)

By establishing that / = :: and _ = part of name, we allow autocompletion to work with any number of packages for any models!