Rails - Creating a select tag from a object hash

前端 未结 4 2102
无人及你
无人及你 2021-02-18 23:13

I need to create a select box from the values available in a Hash.

For instance, I have a \'thing\' and the \'thing\' has a variety of status fields:

1 =         


        
4条回答
  •  清酒与你
    2021-02-18 23:58

    you could do something like

    select "foo", "bar", @hash_object
    

    or

    select "foo", "bar", @hash_object.map { |h| [h.key, h.value] }
    

    I'd probably invert your hash first to make the key point to the value

提交回复
热议问题