4

我在财务模块中有以下模型:

class Finance::BillRec < ActiveRecord::Base
  ...
  has_many :bill_rec_offs, :dependent => :destroy
  ...
end

class Finance::BillRecOff < ActiveRecord::Base
  ...
  belongs_to :bill_rec
  ...
end

我在我的 form_for 上这样做:

<%= form_for([@bill_rec, @bill_rec_off]) do |f| %>
  ...
<% end %>

路线.rb

namespace :finance do
  resources :bill_recs do
    resources :bill_rec_offs
  end
end

和错误:

undefined method `finance_bill_rec_finance_bill_rec_offs_path' for #<#<Class:0x000000070757e0>:0x0000000708bec8>

但是,finance_bill_rec_bill_rec_off_path(@bill_rec_off) 路线运行良好。

如何在带有命名空间的 form_for 和带有模块的嵌套路由上进行操作?

4

1 回答 1

9

尝试

form_for([:finance, @bill_rec, @bill_rec_off])

或者如果它没有帮助

form_for([@bill_rec, @bill_rec_off], url: finance_bill_rec_bill_rec_offs_path(@bill_rec, @bill_rec_off))
于 2012-07-29T22:56:19.777 回答