Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic hash - Ruby on Rails
    primarykey
    data
    text
    <p>the code so far:</p> <pre><code>def queryConnect ... count = 0 #clients is an array of hashes. #channels is an array of hashes. channel_array = [] channels.each do |channel| begin if clients[count]["cid"].to_i == channel["cid"].to_i channel_array &lt;&lt; { "cname" =&gt; channel["channel_name"].transform_escape, "name" =&gt; clients[count]["client_nickname"].transform_escape } count = count + 1 else channel_array &lt;&lt; { "cname" =&gt; channel["channel_name"].transform_escape } end rescue #transform_escape -&gt; some elements are not type string. end end count = 0 channel_array end </code></pre> <p>channels sample input: <code>[{"channel_name" =&gt; "game1", "cid" =&gt; 1}, {"channel_name" =&gt; "game2", "cid" =&gt; 2}, {"channel_name" =&gt; "game3", "cid" =&gt; 3}]</code></p> <p>clients sample input: <code>[{"client_nickname" =&gt; "greg", "cid" =&gt; 1}, {"client_nickname" =&gt; "bob", "cid" =&gt; 1}, {"client_nickname" =&gt; "george", "cid" =&gt; 3}]</code></p> <p>expected output:<code>[{"cname" =&gt; "game1", "name" =&gt; ["greg", "bob"]}]</code></p> <p>The problem: I'm trying to loop through all the channels, if the client's channel id and channel's channel id (cid) match I want to create a hash with the channel name and client name(s) and then push it onto the <code>channel_array</code>. </p> <p>The only issue I'm having now is when there are multiple clients in a channel... How can I dynamically add a key, value pair by iterating through the clients array and still maintaining the condition to see if the channel ids match?</p> <p>I've been beating my head against my text editor for two days on this problem any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload