I have a Rails engine, MyEngine
, that doesn't have an isolated namespace. I'm trying to use the polymorphic helpers to generate links to resources, as per the docs.
An engine route:
# config/routes.rb
...
namespace :admin do
resources :my_resource
end
...
Example output of rake app:routes
(remember, this is an Engine):
admin_my_resources GET /admin/my_resources(.:format) my_engine/admin/my_resources#index
POST /admin/my_resources(.:format) my_engine/admin/my_resources#create
new_admin_my_resource GET /admin/my_resources/new(.:format) my_engine/admin/my_resources#new
edit_admin_my_resource GET /admin/my_resources/:id/edit(.:format) my_engine/admin/my_resources#edit
admin_my_resource PUT /admin/my_resources/:id(.:format) my_engine/admin/my_resources#update
DELETE /admin/my_resources/:id(.:format) my_engine/admin/my_resources#destroy
If my_resource
is an instance of a MyResource
model with ID 12345
, I'd expect:
polymorphic_url([my_engine, :admin, my_resource])
to render:
/my_engine/admin/my_resource/12345
but I was wrong. Instead, I get an exception:
undefined method `admin_my_engine_my_resource_path'...
So, polymorphic_url
is trying to use admin_my_engine_my_resource_path
where it really should be using something more like my_engine.admin_my_resource_path(my_resource)
Rails seems to be adding :admin
the wrong way around... or am I doing it wrong?
namespace
andscope
and I've ended up creating scopes such asscope module: "admin", as: "admin"
to get around it. Thanks! – Hirschfeld