Problem with the association.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problem with the association.

Andrea-18
I have a problem with the association.

I have  the model called Invoice whit the associations:
belongs_to :company
belongs_to :client
belongs_to :type_invoice
has_many :row_invoices
belongs_to :bank
belongs_to :payment

When i create the invoice i use a session variable, so i can add all the
information i wont and I can save all at the end. This is all ok.

def new
        session[:invoice] = Invoice.new # new invoice
        session[:invoice].company = Company.find(1) # load company
        ... # other association
end

Then in my view with the command  <%= debug(session[:invoice]) %> i can
see
company: !ruby/object:Company
  attributes:
    name
    ...


Then when I wont edit the Invoice I load it in the same session variable
(session[:invoice] = Invoice.find(params[:id])) i do:

def edit
        session[:invoice] = Invoice.find(params[:id]) # load attributes
        session[:invoice].company = Company.find(1) # load company
        ... # other association
end

Then in my view with the command  <%= debug(session[:invoice]) %> i can
see
company: # this time is empty... because?


This only for the company association, becouse other association such as
bank perform well.
The name of the field in the database table are correct...
I don't know where find the solution...

Please, help me. Where i mistake.

--sAndrea





--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Rails mailing list
[hidden email]
http://lists.rubyonrails.org/mailman/listinfo/rails