Implement collection_select based upon an array.


I have created an array of time slots as strings and am trying to display them in a form to be selected upon creation.

This is my Appointments controller file.

  helper_method :timeslots

  def timeslots

  @timeslots = ['8:30 AM','9:00 AM','9:30 AM','10:00 AM','10:30 AM','11:00 AM','11:30 AM', '12:00 PM', '12:30 PM', '1:00 PM','1:30 PM', '2:00 PM', '2:30 PM', '3:00 PM', '3:30 PM','4:00 PM']


This is my Appointments form.html.erb file

<div class="field">     <%= f.label :appointment_time %><br>     <%= select "obj", "test", { |name, index>} %> </div>

On the form's page, I just see a blank box with no values. Every time I add a value, the box gets bigger, but there are no values displayed in the rows of the select box.

Each / Each with index returns the same array . You need to use map.

Can you try this

<%= select “obj”, “test”,{ |name, index| [name, index] } %>

Vivek Sampara wrote in post #1163711:

<%= select "obj", "test",{ |name, index| [name, index] } %>

Thanks, it worked