RoR - collection_select from array

collections, date, ruby-on-rails

Solution

Assuming that you mean to use the date strings for both the value (returned from form) and text (displayed in drop-down) of the select then

= f.collection_select :day, @dates, :to_s, :to_s, include_blank: false

This will pass :to_s to each element of the the @dates collection and use the results for the text (param 3) and value (param 4) of the select.

Problem

I've a little array: ``` @dates= ['2013-11-01', '2013-11-02', '2013-11-03', '2013-11-04', '2013-11-05'] ``` how can i put these array in an collection_select in the view? I tried: ``` ... <%= f.collection_select :day, Day.order(:date), :id, @dates, include_blank: false %> ... ```

Original source