Adding prefix to a named route helper under namespace

前端 未结 1 405
悲哀的现实
悲哀的现实 2021-01-01 03:09

This is how a common namespace looks like.

namespace :admin do
  resources :posts
end

And it creates a named route like this one;



        
1条回答
  •  伪装坚强ぢ
    2021-01-01 03:33

    Just try the code in routes.

    namespace :admin, as: '' do
       get '/post/new' => 'posts#new', as: 'new_admin_post'
    end
    

    If you don't want to make admin namespace as nil, then you can do it. for that you need to put that route out of the namespace :admin block in routes

    namespace :admin do
       # your other routes
    end
    
    get '/admin/post/new' => 'admin/posts#new', :as => 'new_admin_post'
    

    0 讨论(0)
提交回复
热议问题