vigetlabs / active_admin_associations

This extends ActiveAdmin to allow for better editing of associations.
MIT License
119 stars 55 forks source link

Allow autocompletion to work for namespaced models. #11

Closed laspluviosillas closed 10 years ago

laspluviosillas commented 11 years ago

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, is converted to the following path:

_ole_coredistributor

Which is then received by the autocomplete processor on 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:

_olecore/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 using the right function, underscore, we allow autocompletion to work with any number of packages for any models!

brianjlandau commented 11 years ago

Thanks for catching this! Can you write tests to cover this so we can make sure no one brakes this in a future commit.

laspluviosillas commented 11 years ago

Eventually :)

Fosome commented 10 years ago

Cleaning up.