Rails,按文件类型选择所有文件

时间:2013-10-23 13:16:42

标签: ruby-on-rails paperclip

例如,我在这里从数据库中提取一些文件名

> Item.pluck(:item_file_name)
=> ["amqp.dll", "readme.txt", "EULA.rtf", "GPL.txt", "adjperm.dll"]

如何按类型选择文件,例如

> txt = Item.where(:item_file_name => '***.txt')
and returns
=> ["GPL.txt",  "readme.txt"] #all txt files

2 个答案:

答案 0 :(得分:1)

这是你的解决方案:

  

txt = Item.select(“item_file_name”)。where(“item_file_name like(?)”,   “%.TXT”)

或者像这样

  

txt = Item.where(“item_file_name like(?)”,   “%.TXT”)摘去(:item_file_name)

答案 1 :(得分:0)

尝试txt = Item.where("item_file_name like (?)", ".txt%").pluck(:item_file_name)