0

I've got two models/views, User and PersonalInfo and I'm trying to call the _form.html.erb partial in the 'user#show' action, but I'm getting an error:

No route matches {:controller=>"personal_info"}

I suspect the issue is that my PersonalInfo routes are nested within the User routes and Rails isn't using the right one, but I don't know how to make it use the right one. Here's the line that's calling the form:

app/views/users/show.html.erb:

<%= render :partial => "/personal_info/form", :locals => {personal_info: @personal_info } %>

app/views/personal_info/_form.html.erb:

<%= form_for @personal_info, url: user_personal_info_index_path, html: { method: :post } do |f| %>

routes.rb:

resources :users do
  resources :personal_info
end

Do I either have to declare something in the personal_info controller or specify the app to use the users/:user_id/personal_info route?

camkidman
  • 185
  • 1
  • 11
  • Given that your `personal_info` controller is at `app/controllers`, you can add the `controller` option to the `resources` declaration in `routes.rb` as: `resources :personal_info, controller: 'personal_infos'` – vee Nov 25 '13 at 05:36
  • @vinodadhikary I still end up getting the same error message, but I think I'm referencing something wrong somewhere.. – camkidman Nov 30 '13 at 04:47
  • In your `form_for` declaration for `url` you also need to pass in `user_id`, i.e `<%= form_for @personal_info, url: user_personal_info_index_path(@user), html: { method: :post } do |f| %>`. Please initiate a chat request if this does not work. Also it appears to me that your `resources :personal_info` should be `resources :personal_infos`(plural). – vee Nov 30 '13 at 05:01
  • @vinodadhikary -- I don't know that I can use the chat system (I have less than 20 reputation), but using what you listed, I'm still getting an error: `No route matches {:action=>"show", :controller=>"personal_infos", :user_id` and the :user_id has a hash of the user object attributes after it. – camkidman Dec 01 '13 at 16:54
  • I was able to get this resolved by changing `<%= form_for @personal_info, url: user_personal_info_index_path, html: { method: :post } do |f| %>` to `<%= form_for @personal_info, url: new_user_personal_info_index_path, html: { method: :post } do |f| %>` – camkidman Dec 04 '13 at 19:51

1 Answers1

0

I was able to get this resolved by changing: <%= form_for @personal_info, url: user_personal_info_index_path, html: { method: :post } do |f| %>

to:

<%= form_for @personal_info, url: new_user_personal_info_index_path, html: { method: :post } do |f| %>

camkidman
  • 185
  • 1
  • 11