如何在命名空间中使用普通资源?

时间:2018-10-14 16:49:27

标签: ruby-on-rails

我的控制器

account
-profiles_controller.rb

我的观看次数

account
-profiles
 --index.html.haml

我的路线

namespace :account do
  resources :profiles
end

当前以此url的形式工作。 http://localhost:3000/account/profiles

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

我该怎么办?

1 个答案:

答案 0 :(得分:1)

使用scope代替namespace

scope module: "account" do
  resources :profiles
end

OR

您也可以将其写为

resources :profiles, module: "account"

有关更多信息,请参见controller-namespaces-and-routing