【发布时间】:2020-09-25 04:18:09
【问题描述】:
所以我试图在命名空间下嵌套资源,但是当我尝试导航到 UserProfile 新页面时,我遇到了以下错误:
ActionController::RoutingError at /users/xxxxxx/user_profiles/new
uninitialized constant AccountManagementPages::UserProfilesController
Did you mean? AccountManagementPages::UsersController
这是在我的routes.rb 文件中设置资源的方式
constraints(AccountManagement) do
namespace :account_management_pages, path: '' do
root to: 'users#new', as: :registration
resources :users, except: %w[index], path_names: { new: 'register' } do
resources :user_profiles
end
end
end
我的控制器和视图的文件结构配置正确(至少我认为是这样)。
这就是我的视图是如何嵌套的。
这就是我配置user_profiles_controller 的方式:
module AccountManagementPages
module Users
class UserProfilesController < ApplicationController
def show; end
def new; end
def edit; end
def create; end
def update; end
end
end
end
和我的模型关联(不要认为这在这里过于相关,但只是以防万一。)
类用户 类用户配置文件 这里的任何帮助将不胜感激。不知道为什么我会遇到这个错误? 提前致谢。
【问题讨论】:
-
“rake routes | grep account_management_pages”怎么说?嵌套路由不需要嵌套文件夹结构。命名空间通常可以,但可以通过指定路径、控制器等来管理。
-
@razvans 它是控制器.. 大声笑.. 我不知道我是如何忽略在路由文件中命名控制器的.. 大声笑.. 谢谢!我已经盯着那个太久了!
标签: ruby-on-rails rails-routing