为什么我现在不能编辑嵌套模型?

时间:2010-12-18 02:20:24

标签: ruby-on-rails nested-routes

我收到以下错误:

undefined method `campaign_fax_path' for #<ActionView::Base:0xb6515200>

我的路线定义如下:

map.resources campaigns, :has_many => :faxes

此处发生错误:

NoMethodError in Faxes#edit

Showing app/views/faxes/_form.html.erb where line #1 raised

我使用一种非常基本的形式:

 <% form_for [@campaign, @fax] do |f| %>
  2   <%= f.error_messages %>
  3   <p>
  4     Campaign:
  5     <%= link_to @campaign.name, campaign_path(@campaign) %>
  6   </p>

当我做耙路线时| grep“campaign_fax *”我得到以下内容:

         campaign_faxes GET    /campaigns/:campaign_id/faxes(.:format)               {:action=>"index", :controller=>"faxes"}
       new_campaign_fax GET    /campaigns/:campaign_id/faxes/new(.:format)           {:action=>"new", :controller=>"faxes"}

2 个答案:

答案 0 :(得分:1)

我假设您使用的是rails 2.3.X

在routes.rb

中尝试此操作
map.resources campaigns do |campaigns|
  campaigns.resources :faxes
end

请参阅:Nested Routes Section of the Rails Guides

答案 1 :(得分:0)

显示app#/ views / faxes / _form.html.erb,其中第1行被提升

也许部分有问题。你检查一下吗?

map.resources campaigns, :has_many => :faxes **is that correct? I don't think so... maybe is:

map.resources campaign, :has_many => :faxes or

map.resources campaign, :has_many => :faxes

map.resources fax, :has_many => :campaigns
相关问题