这就是公共命名空间的样子。
namespace :admin do
resources :posts
end
它创建了一个像这样的命名路由;
new_admin_post_path
这是我的问题;如何将前缀(如本例中的“new”)添加到命名空间下的命名路由?
假设我的路线定义喜欢这个;
namespace :admin do
get 'post/new' => 'posts#new', as: 'post'
end
它创建了一个命名路由,例如;
admin_post_path
我想向此命名路由添加“新”前缀,并使其看起来像new_admin_post_path
我不想用resources
.
只需尝试路线中的代码即可。
namespace :admin, as: '' do
get '/post/new' => 'posts#new', as: 'new_admin_post'
end
如果你不想将 admin 命名空间设置为 nil,那么你可以这样做。为此,您需要将该路由放在命名空间之外:路由中的管理块
namespace :admin do
# your other routes
end
get '/admin/post/new' => 'admin/posts#new', :as => 'new_admin_post'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)