{"issue":{"user":{"id":278411,"login":"davidmathei","url":"https://api.github.com/users/davidmathei","avatar_url":"https://secure.gravatar.com/avatar/efda83579f66286d77e2c209b8f8218a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"efda83579f66286d77e2c209b8f8218a"},"milestone":null,"title":"belongs_to not considered in some routes","created_at":"2011-08-16T14:37:29Z","updated_at":"2011-12-22T22:49:03Z","labels":[{"name":"Bug","url":"https://api.github.com/repos/gregbell/active_admin/labels/Bug","color":"e10c02"}],"state":"open","id":1415551,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"html_url":"https://github.com/gregbell/active_admin/issues/376","closed_at":null,"number":376,"body":"Using belongs_to during registration of a resource naturally uses the \"parent\" as a scope for the \"childs\" overview. The childs controller expects a \"parent_id\" for the index page and the routes ar\r\ne crafted accordingly.\r\n\r\nAs it stands, though, the \"parent_id\" is necessary for the overview but is not processed in all url's where it would be necessary.\r\n\r\nImagine a nesting of Continent, Country and City resources:\r\n    \r\n    ActiveAdmin.register Continent do\r\n      #...\r\n    end\r\n    \r\n    ActiveAdmin.register Country do\r\n      belongs_to :continent\r\n    end\r\n    \r\n    ActiveAdmin.register City do\r\n      belongs_to :country\r\n    end\r\n\r\n\r\nNow the breadcrumb path shown while looking at a city or a city overview does not mention Continent (because it's parsed from the URL which does not contain that datapoint)\r\nand the part linking to the country misses the continent_id. Following the link fails. I found a workaround at least for the breadcrumbs. Works for me, but is possibly not generalizable.\r\n\r\nAdding a comment under a country or city fails in both cases: they only infer admin_city_path and admin_country_path respectively as targets, not admin_country_city_path etc. Would not work anyway because they are not given the extra parameter on invocation.\r\n\r\nFinally the json/csv/xml exports ignore the parent relationship, I managed to work around that by monkeypatching but I'm not sure if that covers all families of URL's to be expected.\r\n\r\nFor the time being handling the comments is more problematic as the routes are defined during namespace registration.\r\n\r\nCould it be that I'm on the wrong path using belongs_to? I can imaging that scope_to would work also, at the expense of adding the parent_id in al URL's which would fail also in the comment case.\r\nAnyone else ran into this problem? Might also be the case that I overlooked something completely obvious ...\r\n\r\nCheers and thanks a lot so far!\r\n\r\n\r\ndownload link fix:\r\n\r\n    class PaginatedCollection < ActiveAdmin::Component\r\n       protected\r\n       def build_download_format_links(formats = [:csv, :xml, :json])\r\n          links = formats.collect do |format|\r\n            #old: link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))\r\n            tmp_p = request.fullpath.split('?')\r\n            new_path = tmp_p[0] + \".#{format}?\" + tmp_p[1..-1].join('?') #the ugly fix\r\n            link_to(format.to_s.upcase, new_path)\r\n          end\r\n          text_node [I18n.t('active_admin.download'), links].flatten.join(\"&nbsp;\").html_safe\r\n       end\r\n    end\r\n\r\nThe breadcrumb fix tries to establish the first notion of an instance mentioned in the path and works itself up along the belongs_to path.","url":"https://api.github.com/repos/gregbell/active_admin/issues/376","comments":6,"assignee":null},"comment":{"user":{"id":163478,"login":"alzeih","url":"https://api.github.com/users/alzeih","avatar_url":"https://secure.gravatar.com/avatar/4f1b82f58e7e3ef7c0db81eb21238aa4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"4f1b82f58e7e3ef7c0db81eb21238aa4"},"created_at":"2011-12-22T22:49:03Z","updated_at":"2011-12-22T22:49:03Z","id":3255943,"body":"I've written the start of a patch for this ( https://github.com/alzeih/active_admin/compare/master...patch-2 ) but it has a couple of caveats that I think should be fixed before it is merged in:\r\n\r\nIt only uses the  `belongs_to :continent, :country` syntax for now - another belongs_to or a block won't nest them like the inherited_resources syntax\r\n\r\n(As above) The routes are only generated by one extra level.\r\n\r\n","url":"https://api.github.com/repos/gregbell/active_admin/issues/comments/3255943"},"action":"created"}