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'
On 30.07.2012, at 2:08, Marcelo Junior <lists@ruby-forum.com> wrote:
> I have the follow models in Finance module:
>
> class Finance::BillRec < ActiveRecord::Base
> ...
> has_many :bill_rec_offs, :dependent => :destroy
> ...
> end
>
> class Finance::BillRecOff < ActiveRecord::Base
> ...
> belongs_to :bill_rec
> ...
> end
>
> I'm doing this on my form_for:
>
> <%= form_for([@bill_rec, @bill_rec_off]) do |f| %>
> ...
> <% end %>
>
> routes.rb
>
> namespace :finance do
> resources :bill_recs do
> resources :bill_rec_offs
> end
> end
>
> And the error:
>
> undefined method `finance_bill_rec_finance_bill_rec_offs_path' for
> #<#<Class:0x000000070757e0>:0x0000000708bec8>
>
> However, the route finance_bill_rec_bill_rec_off_path(@bill_rec_off)
> works well.
>
> How can I do on a form_for with namespace and nested routes with module?
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment