Topic: Model with Nested Attributes Update Error (undefined method firm_path)

i'm trying to update multiple models within one form.
I'm using nested attributes in the following way:

Class Customer:

    class Customer < ActiveRecord::Base
       
        #Associations
        has_one :registered_office
        has_many :responsibles
       
        #Nested Attributes
        accepts_nested_attributes_for :registered_office
        accepts_nested_attributes_for :responsibles
    end

Customer Controller:

    def edit
        @customer = Customer.find(params[:id])     
    end

edit.html.erb:

    <%= form_for(@customer, :multipart => true ) do |customer|  %>
        <input name="_method" type="hidden" value="put" />
        etc... etc...

   
The problem is that if I call:

    http://localhost:3000/customers/x/edit

I have the following error:

> Rails Undefined method `firm_path' for #<#<Class:0x007ff189126a10>:0x007ff189135c18>

Additional infos:
The error is given by the line:

    <%= form_for(@customer, :multipart => true ) do |customer|  %>

And the type of error is:

> NoMethodError in Customers#edit

If I create a new customer instead of loading an existing one in the controller everything work fine.
Suggestions?

Last edited by wedontplay (2012-08-31 06:38:51)

Re: Model with Nested Attributes Update Error (undefined method firm_path)

At what point does the error occur?
You haven't posted any code that refers to the firm_path variable. You need to find that call to firm_path and either fix it so it uses a path you have set up in your routes or you need to dfine the firm_path route.

Not enough information to help further really

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Model with Nested Attributes Update Error (undefined method firm_path)

I think there is a typo, - instead of 'firm_path' may be it should be 'form_path' ? James is right, check your routes.