Options select in rails

How I can manually enter the options of a select, I have been using the following:

<%= f.collection_select :establecimiento_id, Establecimiento.order(:nombre), :id, :nombre, include_blank: true %>

But that is used to select data from a table, I want to create one with the months, will it be necessary to create a table with the months or is there a way to enter in the code what I want?


ANSWERS:


The second param (in your case Establecimiento.order(:nombre)) is the collection for your select. You can pass a array with pairs of values for value and text of that option. For instance, [[1,"January"], [2,"February"] ] and so on will give you the options with the month name, and the value that will be submitted will be the first one of the pair (in that case, the number of month, but could be the name anyway. It depends of what you want to achieve).

Hope it helps. Good luck!


Try:

<%= f.collection_select :establecimiento_id, collection:[[1,"January"], [2,"February"] ], :id, :nombre, include_blank: true %>

I am not sure about the syntax but above answer gave it already away. You can pass options manually. Check API for collection_select:



 MORE:


 ? Apply defaults to namespaced ActiveRecord translations
 ? No redirect on signout from rails app
 ? Shopify API - Draft Orders, Mark as Payment Pending
 ? Convert into array Ruby
 ? truncate by doing "string" + 1 in C
 ? Infinite cycle in code
 ? SHA256 using Openssl causes segmentation fault
 ? C fscanf input format
 ? Search_string in a loop of different files in C
 ? Properties file reading in C (no C# or C++) compiled with minGW