views:

36

answers:

1

In the _form for creating a new Contact, I want to be able to create a drop-down which allows the User to select the Campaign the Contact will belong to.

In the controller, I created a collection called @campaigns.

And I tried to use the following but not getting it to work:

  <p>
    <%= f.label :campaign_id %><br />
    <%= f.collection_select(:contact, :campaign_id, @campaigns, :id, :name) %>
  </p>

Basically, I want to display the available :name of the campaigns, and then submit the campaign_id associated with the selected campaign to the Contact model when it gets saved.

A: 

It looks like you've got one excess attribute

try this

<p>
  <%= f.label :campaign_id %><br />
  <%= f.collection_select :campaign_id, @campaigns, :id, :name %>
</p>
fl00r
let me try this -- the docs showed a fifth which was confusing....
Angela
the fifth is `f` : `f.collection_select`. actually it is first
fl00r
okay so basically :campaign_id represents the attribute for the given form's model, :id is value, and :name is html display....gotcha, thanks
Angela