为什么我现在无法编辑嵌套模型?

发布于 2024-10-08 01:47:30 字数 938 浏览 2 评论 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>

当我执行 rake paths | 时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"}

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/:campaign_id/faxes/new(.:format)           {:action=>"new", :controller=>"faxes"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再见回来 2024-10-15 01:47:30

我假设您正在使用rails 2.3.X

在您的routes.rb 中尝试此操作

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

请参阅: Rails 指南的嵌套路由部分

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

素衣风尘叹 2024-10-15 01:47:30

显示 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文