Rails nested resource issue

狂风中的少年 提交于 2019-12-08 04:05:21

问题


I have a couple of resources, a grant_application, and a household which are related with a has_one

class GrantApplication < ActiveRecord::Base
  has_one :household, :dependent => :destroy 
end

class Household < ActiveRecord::Base
  belongs_to :grant_application
end

..and I also use the following route..

map.resources :grant_applications do |grant|
  grant.resource :household
end

However, I am having real problems when trying to create the form for /grant_applications/1/household/new

Using

<% form_for([:grant_application, @household]) do |f| %>

returns an error:

undefined method 'grant_households_path' for #<ActionView::Base:0x23eda44>

Any ideas?


回答1:


<% form_for(@household, :url => grant_application_household_path(@grant) ) do |f| %>


来源:https://stackoverflow.com/questions/1159107/rails-nested-resource-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!