Forum: Ruby on Rails Problem with the association.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrea (Guest)
on 2005-12-24 18:13
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
This topic is locked and can not be replied to.