提交“创建我的个人资料”后出现错误
路由错误
没有路线匹配 [POST] "/users/3/profiles"
其次,我重新启动了 webbrick cli = "rails s",并且在输入“http://localhost:3000/users/1/profile/new”后收到错误消息“未定义的方法 `user_profiles_path'”。显然我使用了“resource :profile”非嵌套资源。我正在撕扯我的头发,这些错误发生了什么?
<h1>About You</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for ([@user, @profile]) do |f| %>
<%= f.label :name, "First name:" %>
<%= f.text_field :name %>
<%= f.label :surname, "Surname:" %>
<%= f.text_field :surname %>
<%= f.submit "Create my profile", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
resources :users do
resource :profile
end
user_profile POST /users/:user_id/profile(.:format) profiles#create
new_user_profile GET /users/:user_id/profile/new(.:format) profiles#new
edit_user_profile GET /users/:user_id/profile/edit(.:format) profiles#edit
GET /users/:user_id/profile(.:format) profiles#show
PUT /users/:user_id/profile(.:format) profiles#update
DELETE /users/:user_id/profile(.:format) profiles#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root / static_pages#home