gregbell/active_admin — Issue #782: belongs_to breaks collection action routing
Author: dkobozev
Created: 2011-11-24 06:27:56+00:00
State: open

When a resource belongs to parent, duplicate routes are generated for parent, which breaks custom collection actions. Here's an example.

```ruby
ActiveAdmin.register Store do
belongs_to :batch, :optional => true
end

ActiveAdmin.register Batch do

# show csv import form
collection_action :import_csv do
end

# process csv import form
collection_action :import_csv_save, :method => :post do
end
end
```

Here are the routes that are generated in this case: https://gist.github.com/1390730. If you look carefully, you'll notice that `/admin/batches/:id(.:format) ` takes precedence over `/admin/batches/import_csv(.:format)` which results in an error when `/admin/batches/import_csv` is hit. The reason for this is the code that the router generates:

```ruby
# for batches
resources :batch
# ...
end

# for stores
resources :batch
resources :store
end
```

The fix seems pretty easy, just add `:only` in `active_admin/router.rb`, line 63:

```ruby
resources config.belongs_to_config.target.underscored_resource_name.pluralize, :only => [] do
instance_eval &routes_for_belongs_to
end
```