administrate
administrate copied to clipboard
incorrect files location when generated dashboard/controller for namespaced models
rails g administrate:dashboard Name/Model
actual
create app/dashboards/model_dashboard.rb
create app/controllers/admin/model_controller.rb
expected
create app/dashboards/name/model_dashboard.rb
create app/controllers/admin/name/model_controller.rb
Hi @namiwang!
Would you be able to provide an example app where I can see this happening? Which version of administrate
are you using?
Maybe if you have multiple levels of admin users (admin and super admin for example) and each level should see different set of dashboards, so app/dashboards/admin
for admin users and app/dashboards/super_admin
for super admins.
@swetagsanghavi and I took a shot at this today. We discovered that the handling of directory structure occurs in Rails::Generator::NamedBase, and is utilized in the Administrate::Generators::DashboardGenerator methods that create the directories/files.
:mag_right: At a glance, it appears as though simply replacing the use of file_name
with name
in both #create_dashboard_definition
and #create_resource_controller
would satisfy what @namiwang is trying to accomplish.
:x: We got stuck on order dependent failing tests after creating a test for this, which appears to be due to improper cleanup of constants. This can be demonstrated here: stratigos/administrate@d1080a9c3e887a5c8d6ab5a35c14cf53c40f46dc.
:octocat: With that commit, the following forms work perfectly fine:
-
rails g administrate:dashboard foo
-
rails g administrate:dashboard foo/bar
...the latter of which will create the nested directory structure:
create app/dashboards/foo/bar_dashboard.rb
create app/controllers/admin/foo/bars_controller.rb
:shipit: It could be some time before I can devote more focus to this, so if anyone wants to pick up from the work in the linked commit above, feel free. Also feel free to weigh in on if this is a desired/healthy feature for Administrate overall - we hadn't fully inspected what other side effects would be introduced (route generation, or other component generation, for example).
:paperclip: I think it is also helpful to clarify that the :namespace
, in this context, refers to the Generator's namespace (e.g., Admin). The Rails generator for a model makes use of this property when it creates nested directory structure, and Administrate's generator makes use of it to create the /admin directory structure.
I think this might be fixed by https://github.com/thoughtbot/administrate/pull/1812, but that's still a work in progress and it has stalled...