请参阅下面的示例,其中我放了“某些内容”,我只是对要映射的内容感到困惑:
array_ids = ['1','2']
array = array_ids.map(something).join(',')
所以当我这样做时:
order_sql = "FIELD(ID,#{array})"
我明白了:
order_sql = "FIELD(ID,'1','2')"
答案 0 :(得分:1)
您可以执行以下操作:
array_ids = ['1','2']
array = array_ids.map { |id| "'#{id}'" }.join(',')
p array
# => "'1','2'"
order_sql = "FIELD(ID,#{array})"
p order_sql
# => "FIELD(ID,'1','2')"
希望有所帮助!