【发布时间】:2018-01-23 21:27:26
【问题描述】:
我知道有一些类似的问题,但我找不到我的案例。我也检查了那个网站:https://github.com/bitmakerlabs/debugging-guide/wiki/Rails-error:-Routing-Error:-uninitialized-constant 看起来它应该可以工作。找不到问题出在哪里。
错误看起来像:
未初始化的常量 ProfileController
在我的 app/controllers 文件夹中,我有 profiles_controller.rb 文件:
class ProfilesController < ApplicationController
# GET to /users/:user_id/profile/new
def new
# Render blank profile details form
end
end
我在 app/views/profiles/new.html.erb 下有一个视图文件,并使用 <%= link_to "Create your profile!", new_user_profile_path(user_id: current_user.id) if user_signed_in? %> 链接到它。在我的路线中,我有:
new_user_profile_path GET /users/:user_id/profile/new(.:format)
个人资料#新
你能告诉我一个错误吗?我能找到的每个答案都与命名有关,而我的名字对我来说很好(profiles_controller.rb 和 ProfilesController 类)。我错过了一些明显的东西吗?
编辑:
我的 routes.rb 文件 sn-p 用于配置文件:
resources :users do
resources :profile
end
编辑 2:
在我的项目中,一位用户可能只有一份个人资料。路由 ...user/profile/... 比 ...user/profiles/... 更有意义
【问题讨论】:
-
你可以为
resource :users添加你的routes.rb文件的sn-p吗? -
@AnuragAryan 我在问题的末尾添加了这一点。
-
@RockwellRice 它确实被称为 ProfilesController,我相信它应该是复数?但我注意到错误是关于 ProfileController 但我不知道为什么......
-
@RockwellRice 不,从一开始它就是“profiles”文件夹。但是我在 routes.rb 中有“profile”而不是“profiles”。已解决,谢谢!如果您可以将该评论添加为答案,我会将其作为正确答案进行检查。
标签: ruby-on-rails routes