Drop Down Menu Problem

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 %>

<%= f.text_field :title %>

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

<%= f.text_field :duration %>

<%= f.label :exam_at %>

<%= f.datetime_select :exam_at %>

<%= f.label :paper_id %> ID

<%= f.text_field :paper_id %>

<%= f.label :author %>

#AREA OF CODE TO BE FOCUSED ON

<select name=“select”, :author>
Select Author…
<% for author in @authors %>
<%=h author.name %>
<% end %>

#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

I found out.

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

Just for anyone who may have the same problem at some point

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs