当该模型的路由嵌套在当前视图Rails 3中时,使用另一个视图中的部分

时间:2013-11-25 05:24:07

标签: ruby-on-rails ruby ruby-on-rails-3 partials

我有两个模型/观看次数,UserPersonalInfo我试图在_form.html.erb行动中调用'user#show'部分,但我是收到错误:

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

我怀疑问题是我的PersonalInfo路由嵌套在User路由中,而Rails没有使用正确的路由,但我不知道如何使用正确的路由。这是调用表单的行:

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

我是否必须在personal_info控制器中声明某些内容或指定应用以使用users/:user_id/personal_info路由?

1 个答案:

答案 0 :(得分:0)

我能够通过改变来解决这个问题:     <%= form_for @personal_info, url: user_personal_info_index_path, html: { method: :post } do |f| %>

为:

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