Why doesn't this work?
I have an array of Objects, one of the attributes is the db id. I can make the array like so.
qc_parts.map!{|a| a.id}
However when I want to just make it a string. With
qc_parts.map!{|a| a.id}.join(",")
I only get an array out. I've also trie开发者_如何学Cd .to_s
& .to_a
Any idea why this would be happening?
qc_parts.map!{|a| a.id}.join(",")
will return a string, but it will not to put that value into the variable qc_parts
. To do that you have to do
qc_parts = qc_parts.map{|a| a.id}.join(",")
If I've misunderstood, and you actually are seeing the join
method return an array, then something strange is going on.
精彩评论