Jens-Christian,
There are two contacts tables:
company (hm) ↔ (bt) contacts
project (ho) ↔ (bt) project_contacts
(ho might become hm)
project (ho) ↔ (bt) project_products
When creating a new project I copy some of the fields from “contacts” to
“project_contacts”. The following would occcur with only the contacts
table:
When a contact is destroyed (resigns or starts working for a different
company), the project is no longer visible and will generate errors,
‘nill’
issues I assume.
When I run the new_project method a nice list is created (line 23) based
on a
sql query (line 21). When submitting the form and going to
create_project I
get kinda lost. I’m not sure if line 29 is nessecary. And the line from
the
earlier email:
@contact.find_on_id_from_form_somehow.firstname
Should be on line 36, but I’m still figuring out how to get the contents
of a
specific field of a specific table. I’m going to do this for several,
but not
all, fields. (probably: firstname, lastname, telnumber, email, company
name
and central company telnumber). Hope you can give me some pointers.
Thanx a lot!!
Regards,
Gerard.
18 def new_project
19 @project = Project.new
20
21 @contacts_list = Contact.find_by_sql('select t1.name,
t2.firstname, t2.lastname, t2.id from companies AS t1, contacts
AS t2
where t1.id = t2.company_id order by t1.name’)
22
23 @contacts_list = @contacts_list.collect { |c| [ c.name + " -
" +
c.firstname + " " + c.lastname, c.id ] }
24 render_action ‘edit_project’
25
26 end
27
28 def create_project
29 @contact = Contact.new
30 @project = Project.new(@params[‘project’])
31 @project_contact = ProjectContact.new(@params[‘collect’])
32
33 @project.project_contact = @project_contact
34 #breakpoint
35 contact = Contact.find(@params[‘id’][‘collect’])
36 @project.project_contact[‘firstname’] = contact[“firstname”]
37
38 #@project.project_contact.save
39 if @project.save
40 flash[:notice] = ‘Project was successfully created.’
41 redirect_to :action => ‘show_project’, :id => @project.id
42 else
43 render :action => ‘edit_project’
44 end
45 end
On Monday 09 January 2006 14:08, Jens-Christian F. tried to type
something like:
What needs to be done is catch some fields and copy them based on
the id.
@project_contact.firstname =
Class Project
@project.contact = Contact.find(@params[:collect])
InVisible GmbH, Langgrütstrasse 172, 8047 Zürich
Phone: +41 44 401 09 30
http://www.invisible.ch http://not.invisible.ch
–
“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”
My $Grtz =~ Gerard;
~
:wq!