NewbieQ - Relational tables

Hi all,

I’m going nuts on a very simple issue. I know what I want but don’t know
what
to tell rails to do so. I have a very common setup for managing
contacts. A
companies table and a contacts table. As you’ve guessed it’s a one to
many
relationship.
The database is setup with the appropriate foreign keys, the models have
been
generated and I added the “has_many :contacts” and “belongs_to :company”
to
the appropriate models
Having put scaffolds in place and wanting to add a contact, when saving
I get:

ActiveRecord::AssociationTypeMismatch in Work#create
Company expected, got String
(I don’t now what “Company” represents in this case (model, column or
what
not)

What I eventually want when adding a contact is having a dropdown list
with
the company names so the relation is established.

I have the agile book, and the example webshop was a very clear. But I
can’t
seem to implement this. Are there any easy online step-by-step tutorials
how
to go about this, because I’m losing it.

Thanx a lot!

Regards,

Gerard.

Having put scaffolds in place and wanting to add a contact, when saving I get:

ActiveRecord::AssociationTypeMismatch in Work#create
Company expected, got String
(I don’t now what “Company” represents in this case (model, column or what
not)

Scaffold generator works only with one table. It’s strange you got
such message about Compagny that sit on another table.

Please post back your models, and generated controllers & view.
attachments are prefered.

Finally getting somewhere. The relationship thingy seems to be nailed. I’m
afraid of working with scaffold, because I can’t oversee the impact worry I
might loose code. So I’ll do it the manual way.

There’s also a manual way but using the right Helpers :

http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000356

Hi all again,

Finally getting somewhere. The relationship thingy seems to be nailed.
I’m
afraid of working with scaffold, because I can’t oversee the impact
worry I
might loose code. So I’ll do it the manual way.

Nevertheless do I have a question on the code below. The dropdownlist is
in
place. but now al the fields need to be filled. Since I have 20 fields
for a
contact. Is it possible to generate the label - text_field - label -
text_field - etc. iteration dynamically with a loop. (Seems more
managable
like that).

Here’s the catch: The company.id field needs to be ignored because
that’s
already in the drop downlist.

New contact

Company
<% @companies.each do |company| %> <%= company.name %> <% end %>

From here on

Firstname
<%= text_field 'contact', 'firstname' %>

Lastname
<%= text_field 'contact', 'lastname' %>

And another 18 entries like the two up here.

Thanx a lot.

Gerard -hopefully-no-to-demanding- Petersen

On Friday 30 December 2005 11:59, Gerard tried to type something like:

get:
can’t seem to implement this. Are there any easy online step-by-step


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


“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!