activeadmin: Nested belongs_to is broken
I have the following situation:
ActiveAdmin.register Location do
end
ActiveAdmin.register Event do
belongs_to :location
end
ActiveAdmin.register Ticket do
belongs_to :event
end
I would expect these namespaces to work:
- locations
- locations/[id]
- locations/[id]/events
- locations/[id]/events/[id]
- locations/[id]/events/[id]/tickets
- locations/[id]/events/[id]/tickets/[id]
instead the following work
- locations
- locations/[id]
- locations/[id]/events
- locations/[id]/events/[id]
and (kind of surprising)
- events/[id]/tickets
- events/[id]/tickets/[id]
while these don’t work:
- locations/[id]/events/[id]/tickets
- locations/[id]/events/[id]/tickets/[id]
- events
- events/[id]
the last two are on the one hand what I except because events are within locations namespace, but given that the namespace “events” seems to exists for the tickets, that is quite puzzling.
as expected, stuff like
admin_location_event_tickets_path(locationid, eventid)
does not work, neither. (NoMethodError)
admin_event_tickets_path(eventid)
does work and gives a valid path while
admin_event_path(eventid)
also works but gives an invalid path (shouldn’t work at all in my opinion)
the current behavior also breaks the breadcumbs: if you use events/[id]/tickets, the events oder the events/[id] link in the breadcrumbs are broken
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 5
- Comments: 27 (14 by maintainers)
Using ActiveAdmin 1.2.1, Rails 5.1 and this problem still persist. Anyone has a suggestion of how this can be solved?
While I have yet to try your code I find that you can hardly say it’s working.
For example
Still generates
/admin/reports/:report_id/issues
path. The breadcrumbs then offer you to go to/admin/reports
which don’t exist as you could already guess.Since the bug isn’t fixed, a little hack can be done as following:
Instead of having a route like:
locations/[id]/events/[id]/tickets
, we can have a link to/tickets?q[event_id_eq]=[id]
so that we set a filter on the ticket’s event id.link_to 'Tickets', admin_tickets_path(q: { event_id_eq: ticket.id })
assuming we have a varticket
containing the right ticket.Hope this can help
Just hit a similar issue with using
class_name
like this:It turns out inherited_resources doesn’t seem to respect
class_name
we can fix it by usingparent_class: User
as you can see below:We know it was broken somewhere between 1.0.0.pre1 and 1.3.0 since we were upgrading our project to the latest AA when we noticed this was no longer working.
Hope the above workaround saves you guys some time 😃.
It would be nice to have this working at some point, it has been 3 years since this was reported. Did someone get it working and could tell us what needs to be done?