Forum: Ruby on Rails Drop Down Menu Problem

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.
Bef7651e6b8a2a4b5c37ece5783e0d34?d=identicon&s=25 Rik Stott (rikki123s)
on 2009-04-01 20:47
Here is my papers table:

title:string
duration:integer
exam_at:datetime
paper_id:integer
author:string

and here is my author table:

name:string
email:string
telephone:string
author_id:string

I have created views for both of these table, and I have implemented the
CRUD structure for them both, but there is one small problem I have.
when it comes to creating a new paper, and generating the value for the
author value in the papers table, I want to use a select drop down menu
that consists of the names of all the authors in the authors table (so i
can select which author created the paper).

right now I have the html code displayed like this:

<% form_for(@paper) do |f| %>
  <%= f.error_messages %>

  <%= f.label :title %><br />
  <%= f.text_field :title %><br />

  <%= f.label :duration %> (Minutes)<br />
  <%= f.text_field :duration %><br />

  <%= f.label :exam_at %><br />
  <%= f.datetime_select :exam_at %>

  <%= f.label :paper_id %> ID<br />
  <%= f.text_field :paper_id %>

  <%= f.label :author %><br />


  #AREA OF CODE TO BE FOCUSED ON

  <select name="select", :author>
    <option>Select Author...</option>
    <% for author in @authors %>
      <option><%=h author.name %></option>
    <% end %>
  </select>

  #AREA OF CODE TO BE FOCUSED ON


  <%= f.submit "Create" %>
  <% end %>

Obviously this code will produce a drop down menu that shows the names
of all the authors, but will not save to the table, because it is not
being held by 'f'. I was just wondering if anybody new the code for this
(should start with "<%= f.select" I believe.

Hope someone can help
Bef7651e6b8a2a4b5c37ece5783e0d34?d=identicon&s=25 Rik Stott (rikki123s)
on 2009-04-03 03:36
I found out.

  <%= f.collection_select( :author, @authors, :name, :name, {}, {} ) %>

Just for anyone who may have the same problem at some point
This topic is locked and can not be replied to.