2010-12-18 43 views
0

我收到以下錯誤:爲什麼我現在不能編輯嵌套模型?

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"} 
+0

你看到'campaign_faxis' '耙路線'中的任何地方?是的,這是帶有「我」的「faxis」。 – zetetic 2010-12-18 04:37:48

回答

1

我假設你正在使用的軌道2.3.x版本

在你的routes.rb試試這個

map.resources campaigns do |campaigns| 
    campaigns.resources :faxes 
end 

看:Nested Routes Section of the Rails Guides

+0

我修復了它,但通過閱讀指南,無法回想它是什麼。 – Angela 2011-03-17 16:35:43

0

顯示應用程序/視圖/傳真/ _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 
相關問題