railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

Can't use url/path helpers in custom admin view #3567

Closed matssigge closed 1 year ago

matssigge commented 1 year ago

Describe the bug I have a custom action which renders its own view. In this view, I can't use the standard Rails url/path helpers for "normal" routes in my application.

Reproduction steps Let's say I have a specific route in my app, e.g. the following line in routes.rb.

post "/custom_action", to: "custom#custom_action", as: "custom_action"

Create a custom actions like the docs say, and add a view under views/rails_admin/main/custom_action.html.erb. In the view, try to use custom_action_path (e.g. for using as the action attribute of a form tag). When rendering the view, it blows up with undefined local variable or method custom_action_path.

Quick repro I've created a project which demonstrates this behavior at https://github.com/matssigge/rails-admin-test. Clone the project and follow the instructions in README.md to reproduce.

Expected behavior It should be possible to use a route helper for a "main app route" within a RailsAdmin custom action template.

Additional context

I tried asking about this on the mailing list/Google group, but there seems to be nobody home.

mshibuya commented 1 year ago

Since RailsAdmin is built as a Rails Engine with isolated namespace, you need to call main_app.custom_action_path. https://guides.rubyonrails.org/engines.html#routes

matssigge commented 1 year ago

Thank you!