首页 > 解决方案 > 如何在命名空间内使用普通资源?

问题描述

我的控制器

account
-profiles_controller.rb

我的观点

account
-profiles
 --index.html.haml

我的路线

namespace :account do
  resources :profiles
end

目前以这个网址的形式工作。 http://localhost:3000/account/profiles

但我希望它是这样的。 http://localhost:3000/profiles

我该怎么做?

标签: ruby-on-rails

解决方案


使用scope代替namespace

scope module: "account" do
  resources :profiles
end

或者

你也可以写成

resources :profiles, module: "account"

有关详细信息,请参阅控制器命名空间和路由


推荐阅读