Rails - Creating a select tag from a object hash -


I need to create a select box from values ​​available in hash. For example, I have different types of fields near a 'cheese' and 'cheese':

  1 => 'State A' 2 = & gt;  

As soon as Scokewell said:

hash.eich | One | returns an array of form a = [key, value] , so you can type for hash @status_fields :

  & lt;% = collection_select ('object', 'condition', @status_fields ,: first, last:%)  

Alternatively, if you want to show the key in the selection list and put the price list in the selection list value then:

  Lt;% = Archive_style ('object', 'position', @status_filds, last, first)%>  

This will select the option given by the thing. Thats or nothing if the zero is returned

If you do not want to make any selection tied to any object use

  <% = select_tag ('name ', Options_from_collection_for_select (@status_fields, first, last,' 2 '))% & gt;  

Where '2' is the index of the desired selection

PS: I do not have enough reputation to modify or comment on the original post.

>

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -