开发者

Comma Delinated string, of Ids, from Array of Objects. RoR

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜