开发者

Why can't I edit a nested model now?

I get the following error:

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

I have routes defined as follows:

map.resources campaigns, :has_many => :faxes

The error occurs here:

NoMethodError in Faxes#edit

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

I use a pretty basic form:

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

When I do a rake routes | grep "campaign_fax*" I get the following:

         campaign_faxes GET    /campaigns/:campaign_id/faxes(.:format)               {:action=>"index", :controller=>"faxes"}
       new_campaign_fax GET    /campaigns/:c开发者_运维百科ampaign_id/faxes/new(.:format)           {:action=>"new", :controller=>"faxes"}


I'm assuming that you are using rails 2.3.X

Try this in your routes.rb

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

See: The Nested Routes Section of the Rails Guides


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

Maybe there is something wrong in the partial. have you check it?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜