Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More than one resource_admin to the same model #370

Open
mateuszbozek opened this issue Jul 8, 2021 · 4 comments
Open

More than one resource_admin to the same model #370

mateuszbozek opened this issue Jul 8, 2021 · 4 comments

Comments

@mateuszbozek
Copy link

Hi ! Is it any possibility to create more than one admin resource to the same model ? Due to status (value of attribute (boolean) : true, false ) of objects in my model I need two menu items for managing of each parts of objects. Thanks for any answers.

@quantavi
Copy link

quantavi commented Jul 8, 2021

I believe you can have as many admin pages to the same resource as pleased.
Used collection keyword to scope the model, like:4

#first_admin_page.rb
  collection do
    model.where(flag: true)
  end
#second_admin_page.rb
  collection do
    model.where(flag: false)
  end

@PadawanBreslau
Copy link

PadawanBreslau commented Jul 8, 2021

You can easily with

app/admin/test_product_admin.rb
Trestle.resource(:test_product, model: Product)

app/admin/real_product_admin.rb
Trestle.resource(:real_product, model: Product)

And so on. Then you can limit data as stated above, permissions and behaviors. Using this way on production without any problems

@Fedcomp
Copy link

Fedcomp commented Aug 15, 2024

I just faced admin_link_to issue when declaring multiple resources with model: User.
admin_link_to links to wrong resource, i would like to make one of them primary, and the others specialized/secondary, so admin_link_to links to primary resource.

Solved it with this ugly hack:

# app/admin/users_admin.rb
# put this code before Trestle.resource(:user)

# HACK: Ensure this admin module is registered as
#       primary User model page and admin_link_to User keep refering here.
#       Prevents conflict with YouNameConflictingAdminModule
Trestle.registry.instance_variable_get(:@models).delete('User')

In case your admin page is not about users - change it to your needs accordingly.

@spohlenz
Copy link
Member

@Fedcomp Use the register_model: false option when declaring your secondary admin resource:

Trestle.resource(:secondary_users, register_model: false) do
  ...
end

This will ensure that this resource is not used for automatic model lookup when using the admin_link_to helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants