Rails循环逗号分隔字符串

时间:2010-12-03 01:41:58

标签: ruby-on-rails

我有jquery发布

params[:comment][:attachments] = 09ff86a136c05c82a43fed917e5cdbe9bc44e11a82329c6e923935671ed4bf6b, 840bc6197294c6a8c4393803fa16463d28a2520b33d4a0520e905f8b83399d11

然后我希望能够遍历Rails中逗号分隔的列表,这是我到目前为止所拥有的:

params[:comment][:attachments].each do |uuid|
 uuid
end

问题是uuid是否列出了整个字符串..想法在Rails中循环逗号分隔列表?

由于

2 个答案:

答案 0 :(得分:4)

params[:comment][:attachments].split(/, ?/).each ...

答案 1 :(得分:1)

制作一个数组

params[:comment][:attachments].split(",").each do |uuid|
  #stuff
end