简体   繁体   中英

Rails engine path helper doesn't include mount namespace

I have created a rails engine which I'm mounting in the main application's routes.rb:

mount OsuAuth::Engine => '/admin'

I would like to reference a users path helper defined in the engine from my main application, for which I tried:

<%= link_to 'Users', osu_auth.users_path %>

However this generates a path to /users instead of the working path of /admin/users .

Running rake routes also outputs the route without the /admin namespace:

users GET    /users(.:format)                osu_auth/users#index

This seems odd to me. What happened to the /admin namespace where I mounted the engine? How can I get generate the correct path?

Try to use namespace directive:

namespace :admin do
  mount OsuAuth::Engine
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM