简体   繁体   English

不区分大小写和包含ActiveRecord的查询?

[英]Case insensitive and inclusive ActiveRecord queries?

I have views that print out a table of guides that have the word 'farming' in their titles. 我有一些意见,这些意见印出了一张标题为“农业”一词的指南表。

  def farming
   t = Guide.arel_table
    @guides = Guide.where(t[:title].matches('%farming'))
  end

The problem is I want to show all guides that have at least any kind of spelling of the word 'farming' in it. 问题是我想显示所有至少包含 “农业”一词拼写形式的指南。 So "Farming for Dummies" should show up in the search, too. 因此“ Farming for Dummies”也应出现在搜索中。

How do I do this? 我该怎么做呢?

In order to match Farming for Dummies you need to use farming% , ie % should be after the word farming . 为了匹配“ Farming for Dummies您需要使用“ farming% ,即,“ %应在“ farming ”一词之后。

Try the following to return all records with title including the word farming anywhere in title : 尝试执行以下操作以返回所有带有title记录,包括title任何位置的单词farming

def farming
  t = Guide.arel_table
  @guides = Guide.where(t[:title].matches('%farming%'))
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM