1

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.

1 Answer 1

3

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"]
Sign up to request clarification or add additional context in comments.

4 Comments

babai. Thanx. but again need some help plz. "<option value = '#{p (JSON.parse(disp)).map{|h| h['status_name'] }}'>#{p (JSON.parse(disp)).map{|h| h['status_name'] }}</option>" I need the above values in an option list/dropdown. Is the above code correct?
@user19098 As per your question I gave this solution.. But don't know anything about ROR.. So can't help. But my answer will work 100% if you fit it properly in your code base..
Yes it works perfectly as you mentioned. I am able to get it as an array of status names. But was trying to get that names in a dropdown list !
@user19098 Use puts instead of p.. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.