我有两个模型/观看次数,User
和PersonalInfo
我试图在_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
路由?
答案 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| %>