This is because your models are included in other class Finance, and it
is very possible for developer to make a mistake understanding of paths
or whatever stuff which uses .model_name of your classes.
In your case, the concern is - route:
namespace :finance do
resources :bill_recs do
resources :bill_rec_off
end
end
generated ‘finance_bill_rec_bill_rec_off_path()’ - thats right in
‘namespace’ logic.
‘finance’ part in this route is just because you pass the argument
‘namespace’ and not because your model_name is ‘finance_bill_rec’.
But the <%= form_for([@bill_rec, @bill_rec_off]) do |f| %> uses
.polymorphic_path() method, and returns you
‘finance_bill_rec_finance_bill_rec_offs_path’. Twice ‘finance’ in that
case is because .model_name returns ‘finance_bill_rec’ and
‘finance_bill_rec_off’ - thats the clear and real path name you should
implement.
Yeah, we’d better always let Rails operate on their own methods, hidden
from us, like .model_name() or .polymorphic_path().
Ok, working with route:
‘namespace :finance do …’ - is this really what you looking for? I
think you just want to operate with your models under browser’s string
‘/finance/…’, right? Try another approach for that:
resources :bill_recs, :path => ‘/finance’ do
resources :bill_rec_off
end
OR
scope “/finance” do
resources :bill_recs do
resources :bill_rec_off
end
end
Anyway, you should implement
‘finance_bill_rec_finance_bill_rec_offs_path’ without ‘namespace’
finance_bill_rec_bill_rec_offs GET
/finance/bill_recs/:bill_rec_id/bill_rec_offs(.:format)
finance/bill_rec_offs#index
POST
/finance/bill_recs/:bill_rec_id/bill_rec_offs(.:format)
finance/bill_rec_offs#create
new_finance_bill_rec_bill_rec_off GET
/finance/bill_recs/:bill_rec_id/bill_rec_offs/new(.:format)
finance/bill_rec_offs#new
edit_finance_bill_rec_bill_rec_off GET
/finance/bill_recs/:bill_rec_id/bill_rec_offs/:id/edit(.:format)
finance/bill_rec_offs#edit
finance_bill_rec_bill_rec_off GET
/finance/bill_recs/:bill_rec_id/bill_rec_offs/:id(.:format)
finance/bill_rec_offs#show
PUT
/finance/bill_recs/:bill_rec_id/bill_rec_offs/:id(.:format)
finance/bill_rec_offs#update
DELETE
/finance/bill_recs/:bill_rec_id/bill_rec_offs/:id(.:format)
finance/bill_rec_offs#destroy
The routes works well, like <%= link_to “new”,
new_finance_bill_rec_bill_rec_off(@bill_rec) %>