I have a long list of group_ids like so:
@group_ids = @groups.map(&:group_id)
Rails.logger.info @group_ids
[182, 122, 181, 173, 167, 58, 13, 11, 180, 40, 71, 1, 29, 47, 142, 52, 174, 7, 168, 171, 156, 120, 79, 72, 54, 26, 65]
How can I take all 开发者_如何学Gothose group_ids and output:
group_id:11 OR group_id:22 etc
Just do:
@group_ids * " OR "
(Ruby is great)
@group_ids = [182, 122, 181, 173, 167, 58, 13, 11, 180, 40, 71, 1, 29, 47, 142, 52, 174, 7, 168, 171, 156, 120, 79, 72, 54, 26, 65]
@group_ids.map{|id| "group_id:#{id}"}.join(" OR ")
#=> "group_id:182 OR group_id:122 OR group_id:181 OR group_id:173 OR group_id:167 OR group_id:58 OR group_id:13 OR group_id:11 OR group_id:180 OR group_id:40 OR group_id:71 OR group_id:1 OR group_id:29 OR group_id:47 OR group_id:142 OR group_id:52 OR group_id:174 OR group_id:7 OR group_id:168 OR group_id:171 OR group_id:156 OR group_id:120 OR group_id:79 OR group_id:72 OR group_id:54 OR group_id:26 OR group_id:65"
精彩评论