The error occured after submitting “Create my Profile”
Routing Error
No route matches [POST] “/users/3/profiles”
Secondly, I have restarted the webbrick cli = “rails s” and I get error message saying “undefined method `user_profiles_path'” after typing “http://localhost:3000/users/1/profile/new”. Clearly I have used “resource :profile” un nested resources. I am tearing my hair out, what happened with these errors?
<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
As far as I understand, rails has no way of knowing whether
form_for ([@user, @profile])(assuming@profileis a new record) is to be routed to/users/:user_id/profileor/users/:user_id/profiles, with verb POST. In general, it will assume the plural form, so you have to explicitly tell it if you want the singular form by writing