Using a partial from another view while that model's routes are nested in the current view Rails 3

StackOverflow https://stackoverflow.com/questions/20185315

Вопрос

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?

Это было полезно?

Решение

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| %>

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top