Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form_for with module and namespace

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?

like image 883
Marcelo Júnior Avatar asked Jan 15 '23 23:01

Marcelo Júnior


1 Answers

Try

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

or if it doesnt help

form_for([@bill_rec, @bill_rec_off], url: finance_bill_rec_bill_rec_offs_path(@bill_rec, @bill_rec_off))
like image 139
Alper Karapınar Avatar answered Jan 25 '23 10:01

Alper Karapınar