简体   繁体   中英

Iterate array of hashes and display in dropdown in ruby

my array of hash is the below one.

[{"status"=>"Submitted", "reachable"=>false}, 
{"status"=>"Replied", "reachable"=>false}, 
{"status"=>"Answered", "reachable"=>false}, 
{"status"=>"Assigned", "reachable"=>false}, 
{"status"=>"Started", "reachable"=>true}, 
{"status"=>"Closed", "reachable"=>false}, 
{"status"=>"Canceled", "reachable"=>true}]

I need the " status " values and display them in a dropdown in a html with embedded ruby code. Can anyone of you let me know the sample code ? I am pretty much new to ruby and getting confused alot in iterations and displaying the values in the dropdown.

Yes as below:

array = [{"status"=>"Submitted", "reachable"=>false}, 
        {"status"=>"Replied", "reachable"=>false}, 
        {"status"=>"Answered", "reachable"=>false}, 
        {"status"=>"Assigned", "reachable"=>false}, 
        {"status"=>"Started", "reachable"=>true}, 
        {"status"=>"Closed", "reachable"=>false}, 
        {"status"=>"Canceled", "reachable"=>true}]

p array.map{|h| h["status"] }
# >> ["Submitted", "Replied", "Answered", "Assigned", "Started", "Closed", "Canceled"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM