我要求用户能够搜索回形针上传的文件名。查看上传的文档看起来像这样......
2.0.0-p353 :002 > d=Document.last
Document Load (0.4ms) SELECT "documents".* FROM "documents" ORDER BY "documents"."id" DESC LIMIT 1
=> #<Document id: 5, name: "hampton_george_27_70", transcription: "Asheville Nov 8th 1853 received of James A. Patton...", created_at: "2014-08-22 16:10:19", updated_at: "2014-08-22 16:37:51", document_file_name: "hampton_george_27_70.jpeg", document_content_type: "image/jpeg", document_file_size: 519652, document_updated_at: "2014-08-22 16:10:19">
2.0.0-p353 :003 > d.document_file_name
=> "hampton_george_27_70.jpeg"
但这些都不是传统的轨道型号,所以我该如何搜索它们呢?
答案 0 :(得分:3)
Document
似乎是一个模型,因此您可以查询它。例如,使用&#34; george&#34;来搜索文档。在文件名中:
search_term = "george"
documents = Document.where(['document_file_name LIKE ?', "%#{search_term}%"])