本文介绍了Rails嵌套资源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些资源,grant_application和一个与has_one相关的住所
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
但是,我遇到了真正的问题尝试为/ grant_applications / 1 / household / new创建表单时
However, I am having real problems when trying to create the form for /grant_applications/1/household/new
使用
<% form_for([:grant_application, @household]) do |f| %>
返回错误:
undefined method 'grant_households_path' for #<ActionView::Base:0x23eda44>
有什么想法吗?
推荐答案
<% form_for(@household, :url => grant_application_household_path(@grant) ) do |f| %>
这篇关于Rails嵌套资源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!