I am trying to use
options_from_collection_for_select(collection, value_method, text_method, selected = nil)
But I am unable to pass proper parameter to it. What should be type on collection element? (Sample for complete usage will be helpful)
I have to use it with format like Name=AL and ID=23, like it is State name and it Code.
So for using how should I provide the collection object to it.
I have tried with Hash, Map and Array
The 1st parameter of
options_from_collection_for_selectshould be an arbitrary collection (accuratley any objects which has amapmethod), for example anArray.Example with
ArrayofHashes:Of course this is a stupid example, because the 2nd parameter is the method for the value and the 3rd is the method of the name. So the method will call the
to_smethods on theHashitems to fetch theidandvaluefor the<option/>, so this will produce:If you provide proper objects, for example
ActiveRecord::Baseobjects:It will produce a better output: