Mar*_*ior 4 ruby-on-rails form-for nested-form-for
我在财务模块中有以下模型:
class Finance::BillRec < ActiveRecord::Base
...
has_many :bill_rec_offs, :dependent => :destroy
...
end
class Finance::BillRecOff < ActiveRecord::Base
...
belongs_to :bill_rec
...
end
Run Code Online (Sandbox Code Playgroud)
我在我的form_for上这样做:
<%= form_for([@bill_rec, @bill_rec_off]) do |f| %>
...
<% end %>
Run Code Online (Sandbox Code Playgroud)
的routes.rb
namespace :finance do
resources :bill_recs do
resources :bill_rec_offs
end
end
Run Code Online (Sandbox Code Playgroud)
而错误:
undefined method `finance_bill_rec_finance_bill_rec_offs_path' for #<#<Class:0x000000070757e0>:0x0000000708bec8>
Run Code Online (Sandbox Code Playgroud)
但是,路线finance_bill_rec_bill_rec_off_path(@bill_rec_off)效果很好.
如何在带有命名空间的form_for和带有模块的嵌套路由上执行此操作?
尝试
form_for([:finance, @bill_rec, @bill_rec_off])
Run Code Online (Sandbox Code Playgroud)
或者如果它没有帮助
form_for([@bill_rec, @bill_rec_off], url: finance_bill_rec_bill_rec_offs_path(@bill_rec, @bill_rec_off))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2360 次 |
| 最近记录: |